[PATCH 2/5] score: Fix _Thread_queue_Extract_locked()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Apr 1 13:56:12 UTC 2016


We must update the wait flags under protection of the current thread
lock, otherwise a _Thread_Timeout() running on another processor may
interfere.
---
 cpukit/score/src/threadqenqueue.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c
index 803b556..71e93c2 100644
--- a/cpukit/score/src/threadqenqueue.c
+++ b/cpukit/score/src/threadqenqueue.c
@@ -116,10 +116,10 @@ bool _Thread_queue_Extract_locked(
 
   ( *operations->extract )( queue, the_thread );
 
-  _Thread_Wait_set_queue( the_thread, NULL );
-  _Thread_Wait_restore_default_operations( the_thread );
-  _Thread_Lock_restore_default( the_thread );
-
+  /*
+   * We must update the wait flags under protection of the current thread lock,
+   * otherwise a _Thread_Timeout() running on another processor may interfere.
+   */
   success = _Thread_Wait_flags_try_change_critical(
     the_thread,
     THREAD_QUEUE_INTEND_TO_BLOCK,
@@ -133,6 +133,10 @@ bool _Thread_queue_Extract_locked(
     unblock = true;
   }
 
+  _Thread_Wait_set_queue( the_thread, NULL );
+  _Thread_Wait_restore_default_operations( the_thread );
+  _Thread_Lock_restore_default( the_thread );
+
   return unblock;
 }
 
-- 
1.8.4.5




More information about the devel mailing list