forked from Imagelibrary/rtems
posix: pthread_mutexattr_setprioceiling()
Accept all priority values in pthread_mutexattr_setprioceiling(). This is in line with POSIX and FreeBSD. The priority is validated in pthread_mutex_init(). Validate the priority only for priority ceiling mutexes.
This commit is contained in:
@@ -21,12 +21,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <rtems/system.h>
|
|
||||||
#include <rtems/score/coremuteximpl.h>
|
|
||||||
#include <rtems/score/watchdog.h>
|
|
||||||
#include <rtems/posix/muteximpl.h>
|
|
||||||
#include <rtems/posix/priorityimpl.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
|
* 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
|
||||||
*/
|
*/
|
||||||
@@ -39,9 +33,6 @@ int pthread_mutexattr_setprioceiling(
|
|||||||
if ( !attr || !attr->is_initialized )
|
if ( !attr || !attr->is_initialized )
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
if ( !_POSIX_Priority_Is_valid( prioceiling ) )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
attr->prio_ceiling = prioceiling;
|
attr->prio_ceiling = prioceiling;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ int pthread_mutex_init(
|
|||||||
POSIX_Mutex_Control *the_mutex;
|
POSIX_Mutex_Control *the_mutex;
|
||||||
const pthread_mutexattr_t *the_attr;
|
const pthread_mutexattr_t *the_attr;
|
||||||
POSIX_Mutex_Protocol protocol;
|
POSIX_Mutex_Protocol protocol;
|
||||||
|
Priority_Control priority;
|
||||||
|
|
||||||
if ( attr ) the_attr = attr;
|
if ( attr ) the_attr = attr;
|
||||||
else the_attr = &_POSIX_Mutex_Default_attributes;
|
else the_attr = &_POSIX_Mutex_Default_attributes;
|
||||||
@@ -86,12 +87,6 @@ int pthread_mutex_init(
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Validate the priority ceiling field -- should always be valid.
|
|
||||||
*/
|
|
||||||
if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
|
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
|
||||||
/*
|
/*
|
||||||
* Validate the mutex type and set appropriate SuperCore mutex
|
* Validate the mutex type and set appropriate SuperCore mutex
|
||||||
@@ -109,6 +104,14 @@ int pthread_mutex_init(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) {
|
||||||
|
if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) ) {
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priority = _POSIX_Priority_To_core( the_attr->prio_ceiling );
|
||||||
|
}
|
||||||
|
|
||||||
the_mutex = _POSIX_Mutex_Allocate();
|
the_mutex = _POSIX_Mutex_Allocate();
|
||||||
|
|
||||||
if ( !the_mutex ) {
|
if ( !the_mutex ) {
|
||||||
@@ -119,11 +122,11 @@ int pthread_mutex_init(
|
|||||||
the_mutex->protocol = protocol;
|
the_mutex->protocol = protocol;
|
||||||
the_mutex->is_recursive = ( the_attr->type == PTHREAD_MUTEX_RECURSIVE );
|
the_mutex->is_recursive = ( the_attr->type == PTHREAD_MUTEX_RECURSIVE );
|
||||||
|
|
||||||
switch ( the_mutex->protocol ) {
|
switch ( protocol ) {
|
||||||
case POSIX_MUTEX_PRIORITY_CEILING:
|
case POSIX_MUTEX_PRIORITY_CEILING:
|
||||||
_CORE_ceiling_mutex_Initialize(
|
_CORE_ceiling_mutex_Initialize(
|
||||||
&the_mutex->Mutex,
|
&the_mutex->Mutex,
|
||||||
_POSIX_Priority_To_core( the_attr->prio_ceiling )
|
priority
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#define CONFIGURE_INIT
|
#define CONFIGURE_INIT
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include <rtems/score/todimpl.h>
|
#include <rtems/score/todimpl.h>
|
||||||
|
|
||||||
@@ -375,11 +376,13 @@ void *POSIX_Init(
|
|||||||
status = pthread_mutexattr_setprioceiling( NULL, 128 );
|
status = pthread_mutexattr_setprioceiling( NULL, 128 );
|
||||||
rtems_test_assert( status == EINVAL );
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (invalid priority)" );
|
puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority INT_MAX)" );
|
||||||
status = pthread_mutexattr_setprioceiling( &attr, 512 );
|
status = pthread_mutexattr_setprioceiling( &attr, INT_MAX );
|
||||||
if ( status != EINVAL )
|
rtems_test_assert( status == 0 );
|
||||||
printf( "status = %d\n", status );
|
|
||||||
rtems_test_assert( status == EINVAL );
|
puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority INT_MIN)" );
|
||||||
|
status = pthread_mutexattr_setprioceiling( &attr, INT_MIN );
|
||||||
|
rtems_test_assert( status == 0 );
|
||||||
|
|
||||||
puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)" );
|
puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)" );
|
||||||
status = pthread_mutexattr_setprioceiling( &destroyed_attr, -1 );
|
status = pthread_mutexattr_setprioceiling( &destroyed_attr, -1 );
|
||||||
@@ -409,9 +412,13 @@ void *POSIX_Init(
|
|||||||
status = pthread_mutex_init( &Mutex_id, &attr );
|
status = pthread_mutex_init( &Mutex_id, &attr );
|
||||||
rtems_test_assert( status == EINVAL );
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
/* must get around error checks in attribute set routines */
|
puts( "Init: pthread_mutexattr_setprotocol - SUCCESSFUL" );
|
||||||
attr.protocol = PTHREAD_PRIO_INHERIT;
|
status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
|
||||||
attr.prio_ceiling = -1;
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
|
puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL" );
|
||||||
|
status = pthread_mutexattr_setprioceiling( &attr, -1 );
|
||||||
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
puts( "Init: pthread_mutex_init - EINVAL (bad priority ceiling)" );
|
puts( "Init: pthread_mutex_init - EINVAL (bad priority ceiling)" );
|
||||||
status = pthread_mutex_init( &Mutex_id, &attr );
|
status = pthread_mutex_init( &Mutex_id, &attr );
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
*** POSIX TEST 5 ***
|
*** BEGIN OF TEST PSX 5 ***
|
||||||
Init's ID is 0x0b010001
|
Init's ID is 0x0b010001
|
||||||
Init: pthread_mutexattr_init - EINVAL (NULL attr)
|
Init: pthread_mutexattr_init - EINVAL (NULL attr)
|
||||||
Init: pthread_mutexattr_init - SUCCESSFUL
|
Init: pthread_mutexattr_init - SUCCESSFUL
|
||||||
@@ -26,12 +26,15 @@ Init: pthread_mutexattr_getprioceiling - EINVAL (NULL attr)
|
|||||||
Init: pthread_mutexattr_getprioceiling - EINVAL (NULL prioceiling)
|
Init: pthread_mutexattr_getprioceiling - EINVAL (NULL prioceiling)
|
||||||
Init: pthread_mutexattr_getprioceiling - EINVAL (not initialized)
|
Init: pthread_mutexattr_getprioceiling - EINVAL (not initialized)
|
||||||
Init: pthread_mutexattr_setprioceiling - EINVAL (NULL attr)
|
Init: pthread_mutexattr_setprioceiling - EINVAL (NULL attr)
|
||||||
Init: pthread_mutexattr_setprioceiling - EINVAL (invalid priority)
|
Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority INT_MAX)
|
||||||
|
Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority INT_MIN)
|
||||||
Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)
|
Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)
|
||||||
|
|
||||||
Init: pthread_mutex_init - EINVAL (NULL mutex_id)
|
Init: pthread_mutex_init - EINVAL (NULL mutex_id)
|
||||||
Init: pthread_mutex_init - EINVAL (not initialized attr)
|
Init: pthread_mutex_init - EINVAL (not initialized attr)
|
||||||
Init: pthread_mutex_init - EINVAL (bad protocol)
|
Init: pthread_mutex_init - EINVAL (bad protocol)
|
||||||
|
Init: pthread_mutexattr_setprotocol - SUCCESSFUL
|
||||||
|
Init: pthread_mutexattr_setprioceiling - SUCCESSFUL
|
||||||
Init: pthread_mutex_init - EINVAL (bad priority ceiling)
|
Init: pthread_mutex_init - EINVAL (bad priority ceiling)
|
||||||
Init: Resetting mutex attributes
|
Init: Resetting mutex attributes
|
||||||
Init: pthread_mutex_init - ENOSYS (process wide scope)
|
Init: pthread_mutex_init - ENOSYS (process wide scope)
|
||||||
@@ -82,7 +85,7 @@ Init: pthread_mutex_init - SUCCESSFUL
|
|||||||
Init: pthread_mutex_trylock - SUCCESSFUL
|
Init: pthread_mutex_trylock - SUCCESSFUL
|
||||||
Init: pthread_setschedparam - Setting Task2 priority to highest
|
Init: pthread_setschedparam - Setting Task2 priority to highest
|
||||||
Task 2: pthread_mutex_lock unavailable (inherit case)
|
Task 2: pthread_mutex_lock unavailable (inherit case)
|
||||||
Init: pthread_getschedparam - priority = 254
|
Init: pthread_getschedparam - priority = 2
|
||||||
Init: pthread_mutex_unlock - SUCCESSFUL
|
Init: pthread_mutex_unlock - SUCCESSFUL
|
||||||
Task 2: mutex acquired
|
Task 2: mutex acquired
|
||||||
Task 2: unlock Mutex 2
|
Task 2: unlock Mutex 2
|
||||||
@@ -103,7 +106,7 @@ Init: pthread_mutex_setprioceiling - new ceiling = 200
|
|||||||
Init: pthread_mutex_setprioceiling - old ceiling = 254
|
Init: pthread_mutex_setprioceiling - old ceiling = 254
|
||||||
Init: pthread_getschedparam - priority = 2
|
Init: pthread_getschedparam - priority = 2
|
||||||
Init: pthread_mutex_trylock - SUCCESSFUL
|
Init: pthread_mutex_trylock - SUCCESSFUL
|
||||||
Init: pthread_getschedparam - priority = 200
|
Init: pthread_getschedparam - priority = 2
|
||||||
Init: pthread_setschedparam - set Task3 priority to highest
|
Init: pthread_setschedparam - set Task3 priority to highest
|
||||||
Init: Sleep 1 second
|
Init: Sleep 1 second
|
||||||
Task 3: pthread_mutex_lock unavailable (inherit case)
|
Task 3: pthread_mutex_lock unavailable (inherit case)
|
||||||
@@ -116,4 +119,4 @@ Init: pthread_mutex_getprioceiling- ceiling = 200
|
|||||||
Init: pthread_setschedparam - set Init priority to highest
|
Init: pthread_setschedparam - set Init priority to highest
|
||||||
Init: pthread_mutex_lock - EINVAL (priority ceiling violation)
|
Init: pthread_mutex_lock - EINVAL (priority ceiling violation)
|
||||||
Init: Recursive Mutex
|
Init: Recursive Mutex
|
||||||
*** END OF POSIX TEST 5 ***
|
*** END OF TEST PSX 5 ***
|
||||||
|
|||||||
Reference in New Issue
Block a user