[PATCH] score: Get current priority with proper locking

Sebastian Huber sebastian.huber at embedded-brains.de
Wed May 26 12:10:09 UTC 2021


The current priority is a 64-bit integer which should be read under
protection of the right ISR lock to avoid potential issues with
non-atomic loads on 32-bit architectures.

Update #4411.
---
 cpukit/score/src/threadrestart.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 1e91ad7249..93e52876d7 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -54,17 +54,17 @@ static Thread_Zombie_control _Thread_Zombies = {
   .Lock = ISR_LOCK_INITIALIZER( "thread zombies" )
 };
 
-static void _Thread_Raise_real_priority(
-  Thread_Control   *the_thread,
-  Priority_Control  priority
-)
+static void _Thread_Raise_real_priority( Thread_Control *the_thread )
 {
   Thread_queue_Context queue_context;
+  Priority_Control     priority;
 
   _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
   _Thread_Wait_acquire( the_thread, &queue_context );
 
+  priority = _Thread_Get_priority( executing );
+
   if ( priority < the_thread->Real_priority.priority ) {
     _Thread_Priority_change(
       the_thread,
@@ -428,11 +428,8 @@ void _Thread_Cancel(
     _Thread_State_release( the_thread, &lock_context );
     _Thread_Make_zombie( the_thread );
   } else {
-    Priority_Control priority;
-
     _Thread_Try_life_change_request( the_thread, previous, &lock_context );
-    priority = _Thread_Get_priority( executing );
-    _Thread_Raise_real_priority( the_thread, priority );
+    _Thread_Raise_real_priority( the_thread );
   }
 
   _Thread_Dispatch_enable( cpu_self );
-- 
2.26.2



More information about the devel mailing list