posix: Allow PTHREAD_PROCESS_SHARED for condvar

Close #3137.
This commit is contained in:
Sebastian Huber
2017-09-15 13:48:44 +02:00
parent 8230a329d3
commit c030edde3f
3 changed files with 34 additions and 4 deletions

View File

@@ -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 ) {

View File

@@ -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" );

View File

@@ -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 ***