[rtems commit] rtems: Simplify rtems_semaphore_set_priority()

Sebastian Huber sebh at rtems.org
Mon Nov 15 11:38:59 UTC 2021


Module:    rtems
Branch:    master
Commit:    1b5db7926b32a532906489620dfd39047d71cb49
Changeset: http://git.rtems.org/rtems/commit/?id=1b5db7926b32a532906489620dfd39047d71cb49

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Mar 23 16:36:09 2021 +0100

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.

---

 cpukit/rtems/src/semsetpriority.c         | 47 +++++++++++++++----------------
 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 119dd85..97e53c6 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 b337fc6..3cc16ec 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);



More information about the vc mailing list