On Wed, Apr 26, 2017 at 10:59 PM, Joel Sherrill <j...@rtems.org> wrote: > > > On Wed, Apr 26, 2017 at 9:02 PM, Gedare Bloom <ged...@rtems.org> wrote: >> >> I might rather see the switch refactored to an if-then block, since it >> has quite a bit of structure to it now. >> > > How about it includes all cases? > It is better written as an if-else the way it looks now. The switch is unnecessary
> --joel > >> >> On Wed, Apr 26, 2017 at 4:42 PM, Joel Sherrill <j...@rtems.org> wrote: >> > --- >> > cpukit/posix/src/mutexinit.c | 41 >> > +++++++++++++++++++---------------------- >> > 1 file changed, 19 insertions(+), 22 deletions(-) >> > >> > diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c >> > index 47e0bcb..cdbba11 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 >> > -- >> > 1.8.3.1 >> > >> > _______________________________________________ >> > devel mailing list >> > devel@rtems.org >> > http://lists.rtems.org/mailman/listinfo/devel > > _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel