[PATCH] score: Move code block to separate function

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Oct 18 11:16:09 UTC 2021


Move a code block to the new function _Thread_Scheduler_withdraw_nodes()
to make ease code review.
---
 cpukit/score/src/threadscheduler.c | 58 ++++++++++++++++--------------
 1 file changed, 32 insertions(+), 26 deletions(-)

diff --git a/cpukit/score/src/threadscheduler.c b/cpukit/score/src/threadscheduler.c
index 19459e8dec..89d863d080 100644
--- a/cpukit/score/src/threadscheduler.c
+++ b/cpukit/score/src/threadscheduler.c
@@ -29,6 +29,36 @@
 #include <rtems/score/schedulerimpl.h>
 
 #if defined(RTEMS_SMP)
+static void _Thread_Scheduler_withdraw_nodes(
+  Thread_Control *the_thread,
+  Scheduler_Node *scheduler_node
+)
+{
+  while ( scheduler_node != NULL ) {
+    Scheduler_Node          *next;
+    const Scheduler_Control *scheduler;
+    ISR_lock_Context         lock_context;
+
+    next = scheduler_node->Thread.Scheduler_node.next;
+#if defined(RTEMS_DEBUG)
+    scheduler_node->Thread.Scheduler_node.next = NULL;
+#endif
+
+    scheduler = _Scheduler_Node_get_scheduler( scheduler_node );
+
+    _Scheduler_Acquire_critical( scheduler, &lock_context );
+    ( *scheduler->Operations.withdraw_node )(
+      scheduler,
+      the_thread,
+      scheduler_node,
+      THREAD_SCHEDULER_READY
+    );
+    _Scheduler_Release_critical( scheduler, &lock_context );
+
+    scheduler_node = next;
+  }
+}
+
 void _Thread_Scheduler_process_requests( Thread_Control *the_thread )
 {
   ISR_lock_Context  lock_context;
@@ -39,7 +69,6 @@ void _Thread_Scheduler_process_requests( Thread_Control *the_thread )
   scheduler_node = the_thread->Scheduler.requests;
 
   if ( scheduler_node != NULL ) {
-    Scheduler_Node *next;
     Scheduler_Node *remove;
 
     the_thread->Scheduler.requests = NULL;
@@ -47,6 +76,7 @@ void _Thread_Scheduler_process_requests( Thread_Control *the_thread )
 
     do {
       Scheduler_Node_request request;
+      Scheduler_Node        *next;
 
       request = scheduler_node->Thread.request;
       scheduler_node->Thread.request = SCHEDULER_NODE_REQUEST_NOT_PENDING;
@@ -77,31 +107,7 @@ void _Thread_Scheduler_process_requests( Thread_Control *the_thread )
     } while ( scheduler_node != NULL );
 
     _Thread_Scheduler_release_critical( the_thread, &lock_context );
-
-    scheduler_node = remove;
-
-    while ( scheduler_node != NULL ) {
-      const Scheduler_Control *scheduler;
-      ISR_lock_Context         lock_context;
-
-      next = scheduler_node->Thread.Scheduler_node.next;
-#if defined(RTEMS_DEBUG)
-      scheduler_node->Thread.Scheduler_node.next = NULL;
-#endif
-
-      scheduler = _Scheduler_Node_get_scheduler( scheduler_node );
-
-      _Scheduler_Acquire_critical( scheduler, &lock_context );
-      ( *scheduler->Operations.withdraw_node )(
-        scheduler,
-        the_thread,
-        scheduler_node,
-        THREAD_SCHEDULER_READY
-      );
-      _Scheduler_Release_critical( scheduler, &lock_context );
-
-      scheduler_node = next;
-    }
+    _Thread_Scheduler_withdraw_nodes( the_thread, remove );
   } else {
     _Thread_Scheduler_release_critical( the_thread, &lock_context );
   }
-- 
2.31.1



More information about the devel mailing list