summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-09-15 13:14:57 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-09-15 13:57:38 +0200
commit3b47ce73fa67efaeb1c92dc0129efa92f22d747c (patch)
treeadbb3251887d6e07a284bfe10a058c0f08b43e91
parentlibio: Remove rtems_libio_t::driver (diff)
downloadrtems-3b47ce73fa67efaeb1c92dc0129efa92f22d747c.tar.bz2
posix: Allow PTHREAD_PROCESS_SHARED for mutexes
Close #3125.
-rw-r--r--cpukit/posix/include/rtems/posix/posixapi.h15
-rw-r--r--cpukit/posix/src/mutexinit.c10
-rw-r--r--testsuites/psxtests/psx05/init.c9
-rw-r--r--testsuites/psxtests/psx05/psx05.scn2
4 files changed, 25 insertions, 11 deletions
diff --git a/cpukit/posix/include/rtems/posix/posixapi.h b/cpukit/posix/include/rtems/posix/posixapi.h
index 1a64cf7a1d..2441a2ee6f 100644
--- a/cpukit/posix/include/rtems/posix/posixapi.h
+++ b/cpukit/posix/include/rtems/posix/posixapi.h
@@ -26,6 +26,8 @@
#include <rtems/score/threadimpl.h>
#include <rtems/seterr.h>
+#include <pthread.h>
+
/**
* @defgroup POSIXAPI RTEMS POSIX API
*
@@ -125,6 +127,19 @@ RTEMS_INLINE_ROUTINE int _POSIX_Zero_or_minus_one_plus_errno(
} \
return (type *) the_object
+/*
+ * See also The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008,
+ * 2016 Edition, subsection 2.9.9, Synchronization Object Copies and
+ * Alternative Mappings.
+ *
+ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_09
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_Is_valid_pshared( int pshared )
+{
+ return pshared == PTHREAD_PROCESS_PRIVATE ||
+ pshared == PTHREAD_PROCESS_SHARED;
+}
+
/** @} */
#endif
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 08acb539b5..c7161b0daf 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/posix/muteximpl.h>
+#include <rtems/posix/posixapi.h>
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/schedulerimpl.h>
@@ -62,14 +63,9 @@ int pthread_mutex_init(
if ( !the_attr->is_initialized )
return EINVAL;
- /*
- * We only support process private mutexes.
- */
- if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
- return ENOSYS;
-
- if ( the_attr->process_shared != PTHREAD_PROCESS_PRIVATE )
+ if ( !_POSIX_Is_valid_pshared( the_attr->process_shared ) ) {
return EINVAL;
+ }
/*
* Determine the discipline of the mutex
diff --git a/testsuites/psxtests/psx05/init.c b/testsuites/psxtests/psx05/init.c
index cde8733bb0..e524d6f96f 100644
--- a/testsuites/psxtests/psx05/init.c
+++ b/testsuites/psxtests/psx05/init.c
@@ -429,10 +429,13 @@ void *POSIX_Init(
status = pthread_mutexattr_init( &attr );
rtems_test_assert( !status );
- puts( "Init: pthread_mutex_init - ENOSYS (process wide scope)" );
- attr.process_shared = PTHREAD_PROCESS_SHARED;
+ puts( "Init: pthread_mutex_init - process shared scope" );
+ status = pthread_mutexattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
+ rtems_test_assert( status == 0 );
status = pthread_mutex_init( &Mutex_id, &attr );
- rtems_test_assert( status == ENOSYS );
+ rtems_test_assert( status == 0 );
+ status = pthread_mutex_destroy( &Mutex_id );
+ rtems_test_assert( status == 0 );
puts( "Init: pthread_mutex_init - EINVAL (invalid scope)" );
attr.process_shared = -1;
diff --git a/testsuites/psxtests/psx05/psx05.scn b/testsuites/psxtests/psx05/psx05.scn
index 4e66ceabf6..0315eee562 100644
--- a/testsuites/psxtests/psx05/psx05.scn
+++ b/testsuites/psxtests/psx05/psx05.scn
@@ -37,7 +37,7 @@ Init: pthread_mutexattr_setprotocol - SUCCESSFUL
Init: pthread_mutexattr_setprioceiling - SUCCESSFUL
Init: pthread_mutex_init - EINVAL (bad priority ceiling)
Init: Resetting mutex attributes
-Init: pthread_mutex_init - ENOSYS (process wide scope)
+Init: pthread_mutex_init - process shared scope
Init: pthread_mutex_init - EINVAL (invalid scope)
Init: pthread_mutex_init - EINVAL (invalid type)
Init: Resetting mutex attributes