[PATCH 2/3] posix: Allow PTHREAD_PROCESS_SHARED for barriers
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Sep 15 11:58:05 UTC 2017
Close #3126.
---
cpukit/posix/src/pbarrierinit.c | 9 +++------
testsuites/psxtests/psxbarrier01/psxbarrier01.scn | 8 ++++++--
testsuites/psxtests/psxbarrier01/test.c | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
index 956085658b..c14cc0cb90 100644
--- a/cpukit/posix/src/pbarrierinit.c
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -25,6 +25,7 @@
#include <rtems/system.h>
#include <rtems/posix/barrierimpl.h>
+#include <rtems/posix/posixapi.h>
/*
* pthread_barrier_init
@@ -78,12 +79,8 @@ int pthread_barrier_init(
if ( !the_attr->is_initialized )
return EINVAL;
- switch ( the_attr->process_shared ) {
- case PTHREAD_PROCESS_PRIVATE: /* only supported values */
- break;
- case PTHREAD_PROCESS_SHARED:
- default:
- return EINVAL;
+ if ( !_POSIX_Is_valid_pshared( the_attr->process_shared ) ) {
+ return EINVAL;
}
/*
diff --git a/testsuites/psxtests/psxbarrier01/psxbarrier01.scn b/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
index 6b714115ae..d568d8d03e 100644
--- a/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
+++ b/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
@@ -1,4 +1,4 @@
-*** POSIX BARRIER TEST 01 ***
+*** BEGIN OF TEST PSXBARRIER 1 ***
pthread_barrierattr_init( NULL ) -- EINVAL
pthread_barrierattr_setpshared( NULL, private ) -- EINVAL
pthread_barrierattr_setpshared( NULL, shared ) -- EINVAL
@@ -19,6 +19,10 @@ pthread_barrier_init( NULL, NULL, 2 ) -- EINVAL
pthread_barrier_init( &barrier, &attr, 2 ) -- EINVAL
pthread_barrierattr_init( &attr ) -- OK
pthread_barrier_init( &barrier, &attr, 0 ) -- EINVAL
+pthread_barrier_init( &barrier, &attr, 1 ) -- EINVAL
+pthread_barrierattr_setpshared( &attr, shared ) -- OK
+pthread_barrier_init( &barrier, &attr, 1 ) -- OK
+pthread_barrier_destroy( &barrier ) -- OK
pthread_barrier_init( &barrier, NULL, 1 ) -- OK
pthread_barrier_init( &barrier, NULL, 1 ) -- EAGAIN
pthread_barrier_destroy( &barrier ) -- OK
@@ -38,4 +42,4 @@ Init: pthread_create - thread 2 OK
pthread_barrier_wait( &Barrier ) for thread 0x0b010002
pthread_barrier_wait - 0x0b010002 released
pthread_barrier_wait - 0x0b010001 released
-*** END OF POSIX BARRIER TEST 01 ***
+*** END OF TEST PSXBARRIER 1 ***
diff --git a/testsuites/psxtests/psxbarrier01/test.c b/testsuites/psxtests/psxbarrier01/test.c
index bcbb87a467..16e8665b94 100644
--- a/testsuites/psxtests/psxbarrier01/test.c
+++ b/testsuites/psxtests/psxbarrier01/test.c
@@ -161,6 +161,23 @@ int main(
status = pthread_barrier_init( &barrier, &attr, 0 );
rtems_test_assert( status == EINVAL );
+ puts( "pthread_barrier_init( &barrier, &attr, 1 ) -- EINVAL" );
+ attr.process_shared = -1;
+ status = pthread_barrier_init( &barrier, &attr, 1 );
+ rtems_test_assert( status == EINVAL );
+
+ puts( "pthread_barrierattr_setpshared( &attr, shared ) -- OK" );
+ status = pthread_barrierattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
+ rtems_test_assert( status == 0 );
+
+ puts( "pthread_barrier_init( &barrier, &attr, 1 ) -- OK" );
+ status = pthread_barrier_init( &barrier, &attr, 1 );
+ rtems_test_assert( status == 0 );
+
+ puts( "pthread_barrier_destroy( &barrier ) -- OK" );
+ status = pthread_barrier_destroy( &barrier );
+ rtems_test_assert( status == 0 );
+
/* allocating too many */
puts( "pthread_barrier_init( &barrier, NULL, 1 ) -- OK" );
status = pthread_barrier_init( &barrier, NULL, 1 );
--
2.12.3
More information about the devel
mailing list