diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-27 08:02:03 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-30 16:16:23 +0200 |
commit | 5a598ac99b0de720a04afc5e2ac6764117589b90 (patch) | |
tree | 811d57df33c0f4fcc1cce61095cb5c0a33eadd7c /cpukit/posix/src/mutexinit.c | |
parent | posix: Delete POSIX_Mutex_Protocol::process_shared (diff) | |
download | rtems-5a598ac99b0de720a04afc5e2ac6764117589b90.tar.bz2 |
score: Add CORE mutex variants
Add CORE_recursive_mutex_Control and CORE_ceiling_mutex_Control to avoid
the run-time evaluation of attributes to figure out how a particular
mutex methods should behave. Start with the no protocol variants. This
eliminates the CORE_MUTEX_DISCIPLINES_FIFO and
CORE_MUTEX_DISCIPLINES_PRIORITY disciplines.
Diffstat (limited to 'cpukit/posix/src/mutexinit.c')
-rw-r--r-- | cpukit/posix/src/mutexinit.c | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c index d90b391c9d..f2912ead18 100644 --- a/cpukit/posix/src/mutexinit.c +++ b/cpukit/posix/src/mutexinit.c @@ -33,10 +33,9 @@ int pthread_mutex_init( const pthread_mutexattr_t *attr ) { - POSIX_Mutex_Control *the_mutex; - CORE_mutex_Attributes *the_mutex_attr; - const pthread_mutexattr_t *the_attr; - CORE_mutex_Disciplines the_discipline; + POSIX_Mutex_Control *the_mutex; + const pthread_mutexattr_t *the_attr; + POSIX_Mutex_Protocol protocol; if ( attr ) the_attr = attr; else the_attr = &_POSIX_Mutex_Default_attributes; @@ -75,13 +74,13 @@ int pthread_mutex_init( */ switch ( the_attr->protocol ) { case PTHREAD_PRIO_NONE: - the_discipline = CORE_MUTEX_DISCIPLINES_FIFO; + protocol = POSIX_MUTEX_NO_PROTOCOL; break; case PTHREAD_PRIO_INHERIT: - the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; + protocol = POSIX_MUTEX_PRIORITY_INHERIT; break; case PTHREAD_PRIO_PROTECT: - the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; + protocol = POSIX_MUTEX_PRIORITY_CEILING; break; default: return EINVAL; @@ -117,21 +116,41 @@ int pthread_mutex_init( return EAGAIN; } - the_mutex_attr = &the_mutex->Mutex.Attributes; - - if ( the_attr->type == PTHREAD_MUTEX_RECURSIVE ) - the_mutex_attr->lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES; - else - the_mutex_attr->lock_nesting_behavior = CORE_MUTEX_NESTING_IS_ERROR; - the_mutex_attr->only_owner_release = true; - the_mutex_attr->priority_ceiling = - _POSIX_Priority_To_core( the_attr->prio_ceiling ); - the_mutex_attr->discipline = the_discipline; - - /* - * Must be initialized to unlocked. - */ - _CORE_mutex_Initialize( &the_mutex->Mutex, NULL, the_mutex_attr, false ); + the_mutex->protocol = protocol; + the_mutex->is_recursive = ( the_attr->type == PTHREAD_MUTEX_RECURSIVE ); + + if ( protocol == POSIX_MUTEX_NO_PROTOCOL ) { + _CORE_recursive_mutex_Initialize( + &the_mutex->Mutex.Recursive + ); + } else { + CORE_mutex_Attributes the_mutex_attr; + + if ( the_attr->type == PTHREAD_MUTEX_RECURSIVE ) { + the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES; + } else { + the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_IS_ERROR; + } + + the_mutex_attr.priority_ceiling = + _POSIX_Priority_To_core( the_attr->prio_ceiling ); + + if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) { + the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; + } else { + the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; + } + + /* + * Must be initialized to unlocked. + */ + _CORE_mutex_Initialize( + &the_mutex->Mutex.Recursive.Mutex, + NULL, + &the_mutex_attr, + false + ); + } _Objects_Open_u32( &_POSIX_Mutex_Information, &the_mutex->Object, 0 ); |