[rtems commit] posix: Allow PTHREAD_PROCESS_SHARED for rwlocks

Sebastian Huber sebh at rtems.org
Fri Sep 22 06:46:50 UTC 2017


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Sep 22 08:22:11 2017 +0200

posix: Allow PTHREAD_PROCESS_SHARED for rwlocks

Close #3153.

---

 cpukit/posix/src/prwlockinit.c         | 30 +++++++--------------------
 testsuites/psxtests/psxrwlock01/test.c | 38 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
index 34ab1ae..ffce814 100644
--- a/cpukit/posix/src/prwlockinit.c
+++ b/cpukit/posix/src/prwlockinit.c
@@ -58,9 +58,7 @@ int pthread_rwlock_init(
   const pthread_rwlockattr_t *attr
 )
 {
-  POSIX_RWLock_Control        *the_rwlock;
-  pthread_rwlockattr_t         default_attr;
-  const pthread_rwlockattr_t  *the_attr;
+  POSIX_RWLock_Control *the_rwlock;
 
   /*
    *  Error check parameters
@@ -68,28 +66,14 @@ int pthread_rwlock_init(
   if ( !rwlock )
     return EINVAL;
 
-  /*
-   * If the user passed in NULL, use the default attributes
-   */
-  if ( attr ) {
-    the_attr = attr;
-  } else {
-    (void) pthread_rwlockattr_init( &default_attr );
-    the_attr = &default_attr;
-  }
-
-  /*
-   * Now start error checking the attributes that we are going to use
-   */
-  if ( !the_attr->is_initialized )
-    return EINVAL;
+  if ( attr != NULL ) {
+    if ( !attr->is_initialized ) {
+      return EINVAL;
+    }
 
-  switch ( the_attr->process_shared ) {
-    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
-      break;
-    case PTHREAD_PROCESS_SHARED:
-    default:
+    if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) {
       return EINVAL;
+    }
   }
 
   the_rwlock = _POSIX_RWLock_Allocate();
diff --git a/testsuites/psxtests/psxrwlock01/test.c b/testsuites/psxtests/psxrwlock01/test.c
index e201293..268f581 100644
--- a/testsuites/psxtests/psxrwlock01/test.c
+++ b/testsuites/psxtests/psxrwlock01/test.c
@@ -90,6 +90,42 @@ void *WriteLockThread(void *arg)
   return NULL;
 }
 
+static void test_pshared_init(void)
+{
+  pthread_rwlock_t rwlock;
+  pthread_rwlockattr_t attr;
+  int eno;
+
+  eno = pthread_rwlockattr_init(&attr);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlock_init(&rwlock, &attr);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlock_destroy(&rwlock);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlock_init(&rwlock, &attr);
+  rtems_test_assert(eno == 0);
+
+  eno = pthread_rwlock_destroy(&rwlock);
+  rtems_test_assert(eno == 0);
+
+  attr.process_shared = -1;
+
+  eno = pthread_rwlock_init(&rwlock, &attr);
+  rtems_test_assert(eno == EINVAL);
+
+  eno = pthread_rwlockattr_destroy(&attr);
+  rtems_test_assert(eno == 0);
+}
+
 /*
  *  main entry point to the test
  */
@@ -113,6 +149,8 @@ int main(
 
   TEST_BEGIN();
 
+  test_pshared_init();
+
   /*************** NULL POINTER CHECKS *****************/
   puts( "pthread_rwlockattr_init( NULL ) -- EINVAL" );
   status = pthread_rwlockattr_init( NULL );




More information about the vc mailing list