diff options
author | Joel Sherrill <joel@rtems.org> | 2017-04-26 15:42:09 -0500 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2017-04-26 15:42:09 -0500 |
commit | c16d45a551d0a3fd65bc76c1f7e159445c9b247b (patch) | |
tree | 09f2b60df888b90d9d73b1b4bc571c83d20b3152 /cpukit/posix/src/mutexinit.c | |
parent | virtex5/startup/dummy_console.c: Use <rtems/bspIo.h> and <rtems/console.h> fo... (diff) | |
download | rtems-c16d45a551d0a3fd65bc76c1f7e159445c9b247b.tar.bz2 |
posix/src/mutexinit.c: Reorder to make priority a scoped variable
Diffstat (limited to '')
-rw-r--r-- | cpukit/posix/src/mutexinit.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c index 47e0bcba73..cdbba11f5e 100644 --- a/cpukit/posix/src/mutexinit.c +++ b/cpukit/posix/src/mutexinit.c @@ -38,10 +38,6 @@ int pthread_mutex_init( const pthread_mutexattr_t *the_attr; POSIX_Mutex_Protocol protocol; const Scheduler_Control *scheduler; - Priority_Control priority; - - /* initialize to avoid warning for used uninitialized */ - priority = 0; if ( attr ) the_attr = attr; else the_attr = &_POSIX_Mutex_Default_attributes; @@ -109,23 +105,6 @@ int pthread_mutex_init( } #endif - if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) { - int prio_ceiling; - bool valid; - - scheduler = _Thread_Scheduler_get_home( _Thread_Get_executing() ); - prio_ceiling = the_attr->prio_ceiling; - - if ( prio_ceiling == INT_MAX ) { - prio_ceiling = _POSIX_Priority_Get_maximum( scheduler ); - } - - priority = _POSIX_Priority_To_core( scheduler, prio_ceiling, &valid ); - if ( !valid ) { - return EINVAL; - } - } - the_mutex = _POSIX_Mutex_Allocate(); if ( !the_mutex ) { @@ -137,9 +116,27 @@ int pthread_mutex_init( the_mutex->is_recursive = ( the_attr->type == PTHREAD_MUTEX_RECURSIVE ); switch ( protocol ) { - case POSIX_MUTEX_PRIORITY_CEILING: + case POSIX_MUTEX_PRIORITY_CEILING: { + int prio_ceiling; + bool valid; + Priority_Control priority; + + scheduler = _Thread_Scheduler_get_home( _Thread_Get_executing() ); + prio_ceiling = the_attr->prio_ceiling; + + if ( prio_ceiling == INT_MAX ) { + prio_ceiling = _POSIX_Priority_Get_maximum( scheduler ); + } + + priority = _POSIX_Priority_To_core( scheduler, prio_ceiling, &valid ); + if ( !valid ) { + _POSIX_Mutex_Free(the_mutex); + _Objects_Allocator_unlock(); + return EINVAL; + } _CORE_ceiling_mutex_Initialize( &the_mutex->Mutex, scheduler, priority ); break; + } default: _Assert( the_mutex->protocol == POSIX_MUTEX_NO_PROTOCOL |