posix: Allow PTHREAD_PROCESS_SHARED for mutexes

Close #3125.
This commit is contained in:
Sebastian Huber
2017-09-15 13:14:57 +02:00
parent 8fa75d35cb
commit 3b47ce73fa
4 changed files with 25 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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