[rtems commit] posix: Allow PTHREAD_PROCESS_SHARED for condvar

Sebastian Huber sebh at rtems.org
Mon Sep 18 05:00:32 UTC 2017


Module:    rtems
Branch:    master
Commit:    c030edde3f76f23d6fe64df940a8ca059f0404e6
Changeset: http://git.rtems.org/rtems/commit/?id=c030edde3f76f23d6fe64df940a8ca059f0404e6

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Sep 15 13:48:44 2017 +0200

posix: Allow PTHREAD_PROCESS_SHARED for condvar

Close #3137.

---

 cpukit/posix/src/condinit.c         |  7 +++++--
 testsuites/psxtests/psx10/init.c    | 19 +++++++++++++++++++
 testsuites/psxtests/psx10/psx10.scn | 12 ++++++++++--
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c
index e863dcd..8d3aa8e 100644
--- a/cpukit/posix/src/condinit.c
+++ b/cpukit/posix/src/condinit.c
@@ -19,6 +19,7 @@
 #endif
 
 #include <rtems/posix/condimpl.h>
+#include <rtems/posix/posixapi.h>
 
 /**
  *  11.4.2 Initializing and Destroying a Condition Variable,
@@ -38,12 +39,14 @@ int pthread_cond_init(
   /*
    *  Be careful about attributes when global!!!
    */
-  if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
-    return EINVAL;
 
   if ( !the_attr->is_initialized )
     return EINVAL;
 
+  if ( !_POSIX_Is_valid_pshared( the_attr->process_shared ) ) {
+    return EINVAL;
+  }
+
   the_cond = _POSIX_Condition_variables_Allocate();
 
   if ( !the_cond ) {
diff --git a/testsuites/psxtests/psx10/init.c b/testsuites/psxtests/psx10/init.c
index a37e14e..24265ba 100644
--- a/testsuites/psxtests/psx10/init.c
+++ b/testsuites/psxtests/psx10/init.c
@@ -115,6 +115,25 @@ void *POSIX_Init(
   rtems_test_assert( status == EINVAL );
   puts( "Init: pthread_cond_destroy - EINVAL (cond invalid)" );
 
+/* pshared tests */
+
+  puts( "Init: pthread_cond_init - EINVAL (invalid pshared)" );
+  attr.process_shared = -1;
+  status = pthread_cond_init( &cond, &attr );
+  rtems_test_assert( status == EINVAL );
+
+  puts( "Init: pthread_condattr_setpshared - PTHREAD_PROCESS_SHARED" );
+  status = pthread_condattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
+  rtems_test_assert( status == 0 );
+
+  puts( "Init: pthread_cond_init - OK" );
+  status = pthread_cond_init( &cond, &attr );
+  rtems_test_assert( status == 0 );
+
+  puts( "Init: pthread_cond_destroy - OK" );
+  status = pthread_cond_destroy( &cond );
+  rtems_test_assert( status == 0 );
+
 /* initiailize the attribute for the rest of the test */
 
   puts( "Init: pthread_cond_init - attr" );
diff --git a/testsuites/psxtests/psx10/psx10.scn b/testsuites/psxtests/psx10/psx10.scn
index 962540d..2c70df8 100644
--- a/testsuites/psxtests/psx10/psx10.scn
+++ b/testsuites/psxtests/psx10/psx10.scn
@@ -1,4 +1,4 @@
-*** POSIX TEST 10 ***
+*** BEGIN OF TEST PSX 10 ***
 Init: pthread_condattr_init
 Init: pthread_condattr_init - EINVAL (attribute invalid)
 Init: pthread_condattr_destroy
@@ -15,12 +15,18 @@ Init: pthread_cond_init - EINVAL (attr not initialized)
 Init: pthread_cond_init - ENOMEM (too many conds)
 Init: pthread_cond_destroy
 Init: pthread_cond_destroy - EINVAL (cond invalid)
+Init: pthread_cond_init - EINVAL (invalid pshared)
+Init: pthread_condattr_setpshared - PTHREAD_PROCESS_SHARED
+Init: pthread_cond_init - OK
+Init: pthread_cond_destroy - OK
 Init: pthread_cond_init - attr
+
 Init: sleep to switch to Task_1
 Task_1: ID is 0x0b010002
 Task_1: pthread_cond_wait
 Init: pthread_cond_destroy - EBUSY (task1 waiting)
 Init: pthread_cond_signal
+
 Init: sleep - switch to Task_1 and Task_2
 Task_1: back from pthread_cond_wait release mutex
 Task_1: pthread_cond_wait
@@ -34,6 +40,7 @@ Task_2: back from pthread_cond_wait release mutex
 Task_2: task exit
 Init: pthread_cond_timedwait for 3 seconds
 Init: pthread_cond_timedwait - ETIMEDOUT - (mutex not acquired)
+
 Init: pthread_cond_signal - EINVAL (cond invalid)
 Init: pthread_cond_broadcast - EINVAL (cond invalid)
 Init: pthread_cond_wait - EINVAL (cond invalid)
@@ -45,6 +52,7 @@ Init: pthread_cond_timedwait - ETIMEDOUT (abstime->tv_sec < current time)
 Init: pthread_cond_timedwait - ETIMEDOUT (abstime->tv_nsec < current time)
 Init: pthread_cond_wait - EINVAL (mutex not locked before call)
 Init: pthread_cond_timedwait - EINVAL (mutex not locked before call)
+
 Init: sleep - switch to Task_3
 Task_3: ID is 0x0b010004
 Task_3: pthread_cond_wait
@@ -52,4 +60,4 @@ Init: pthread_cond_signal
 Init: sleep - switch to Task_3
 Task_3: pthread_cond_wait - EINVAL (mutex not locked after signal)
 Task_3: task exit
-*** END OF POSIX TEST 10 ***
+*** END OF TEST PSX 10 ***




More information about the vc mailing list