[PATCH v2 4/4] posix/src/mutexinit.c: Reorder to make priority a scoped variable
Joel Sherrill
joel at rtems.org
Thu Apr 27 21:55:23 UTC 2017
On Thu, Apr 27, 2017 at 3:40 PM, Gedare Bloom <gedare at rtems.org> wrote:
> On Wed, Apr 26, 2017 at 10:59 PM, Joel Sherrill <joel at rtems.org> wrote:
> >
> >
> > On Wed, Apr 26, 2017 at 9:02 PM, Gedare Bloom <gedare at 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
>
I tested and committed a fix which does this. Yell if it sucks.
--joel
>
> > --joel
> >
> >>
> >> On Wed, Apr 26, 2017 at 4:42 PM, Joel Sherrill <joel at 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 at rtems.org
> >> > http://lists.rtems.org/mailman/listinfo/devel
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20170427/37a183d2/attachment-0002.html>
More information about the devel
mailing list