diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-03-23 16:36:09 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-11-15 11:14:12 +0100 |
commit | 1b5db7926b32a532906489620dfd39047d71cb49 (patch) | |
tree | a818e8d4d0ab9b44131ab2b619985412c58d8e7b | |
parent | score: Fix _CORE_ceiling_mutex_Set_priority() (diff) | |
download | rtems-1b5db7926b32a532906489620dfd39047d71cb49.tar.bz2 |
rtems: Simplify rtems_semaphore_set_priority()
Do not write to the object referenced by old_priority in error paths.
This is in line with other directives.
-rw-r--r-- | cpukit/rtems/src/semsetpriority.c | 47 | ||||
-rw-r--r-- | testsuites/smptests/smpscheduler02/init.c | 2 |
2 files changed, 23 insertions, 26 deletions
diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c index 119dd85d77..97e53c6584 100644 --- a/cpukit/rtems/src/semsetpriority.c +++ b/cpukit/rtems/src/semsetpriority.c @@ -29,20 +29,6 @@ #include <rtems/rtems/tasksimpl.h> #include <rtems/score/schedulerimpl.h> -static rtems_status_code _Semaphore_Is_scheduler_valid( - const CORE_ceiling_mutex_Control *the_mutex, - const Scheduler_Control *scheduler -) -{ -#if defined(RTEMS_SMP) - if ( scheduler != _CORE_ceiling_mutex_Get_scheduler( the_mutex ) ) { - return RTEMS_NOT_DEFINED; - } -#endif - - return RTEMS_SUCCESSFUL; -} - static rtems_status_code _Semaphore_Set_priority( Semaphore_Control *the_semaphore, const Scheduler_Control *scheduler, @@ -51,7 +37,6 @@ static rtems_status_code _Semaphore_Set_priority( Thread_queue_Context *queue_context ) { - rtems_status_code sc; bool valid; Priority_Control core_priority; Priority_Control old_priority; @@ -73,16 +58,26 @@ static rtems_status_code _Semaphore_Set_priority( switch ( variant ) { case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING: - sc = _Semaphore_Is_scheduler_valid( - &the_semaphore->Core_control.Mutex, - scheduler - ); +#if defined(RTEMS_SMP) + if ( + scheduler != _CORE_ceiling_mutex_Get_scheduler( + &the_semaphore->Core_control.Mutex + ) + ) { + _Thread_queue_Release( + &the_semaphore->Core_control.Wait_queue, + queue_context + ); + + return RTEMS_NOT_DEFINED; + } +#endif old_priority = _CORE_ceiling_mutex_Get_priority( &the_semaphore->Core_control.Mutex ); - if ( sc == RTEMS_SUCCESSFUL && new_priority != RTEMS_CURRENT_PRIORITY ) { + if ( new_priority != RTEMS_CURRENT_PRIORITY ) { _CORE_ceiling_mutex_Set_priority( &the_semaphore->Core_control.Mutex, core_priority @@ -105,7 +100,6 @@ static rtems_status_code _Semaphore_Set_priority( ); } - sc = RTEMS_SUCCESSFUL; break; #endif default: @@ -115,9 +109,12 @@ static rtems_status_code _Semaphore_Set_priority( || variant == SEMAPHORE_VARIANT_SIMPLE_BINARY || variant == SEMAPHORE_VARIANT_COUNTING ); - old_priority = 0; - sc = RTEMS_NOT_DEFINED; - break; + _Thread_queue_Release( + &the_semaphore->Core_control.Wait_queue, + queue_context + ); + + return RTEMS_NOT_DEFINED; } cpu_self = _Thread_queue_Dispatch_disable( queue_context ); @@ -129,7 +126,7 @@ static rtems_status_code _Semaphore_Set_priority( _Thread_Dispatch_enable( cpu_self ); *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority ); - return sc; + return RTEMS_SUCCESSFUL; } rtems_status_code rtems_semaphore_set_priority( diff --git a/testsuites/smptests/smpscheduler02/init.c b/testsuites/smptests/smpscheduler02/init.c index b337fc667e..3cc16ec68c 100644 --- a/testsuites/smptests/smpscheduler02/init.c +++ b/testsuites/smptests/smpscheduler02/init.c @@ -282,7 +282,7 @@ static void test(void) prio = 1; sc = rtems_semaphore_set_priority(cmtx_id, scheduler_b_id, prio, &prio); rtems_test_assert(sc == RTEMS_NOT_DEFINED); - rtems_test_assert(prio == 2); + rtems_test_assert(prio == 1); } CPU_ZERO(&cpuset); |