[rtems commit] score: Fix debug assert

Sebastian Huber sebh at rtems.org
Mon Aug 31 15:30:44 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Aug 31 17:07:19 2020 +0200

score: Fix debug assert

Do not access executing->current_state outside the protection of the
thread state lock.  Add missing state with a comment.

---

 cpukit/score/src/threadrestart.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 4e892f7..8654f57 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -336,6 +336,18 @@ void _Thread_Life_action_handler(
 
   _Thread_State_acquire( executing, lock_context );
 
+  /*
+   * The executing thread runs with thread dispatching disabled right now.
+   * Other threads may have suspended the executing thread.  The thread life
+   * handler may run in parallel with _Thread_Add_life_change_request() which
+   * may have set STATES_LIFE_IS_CHANGING.
+   */
+  _Assert(
+    executing->current_state == STATES_READY
+      || executing->current_state == STATES_SUSPENDED
+      || executing->current_state == STATES_LIFE_IS_CHANGING
+  );
+
   _Thread_Change_life_locked(
     executing,
     THREAD_LIFE_PROTECTED | THREAD_LIFE_RESTARTING,
@@ -348,10 +360,6 @@ void _Thread_Life_action_handler(
   _Assert(
     _Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
   );
-  _Assert(
-    executing->current_state == STATES_READY
-      || executing->current_state == STATES_SUSPENDED
-  );
 
   _User_extensions_Destroy_iterators( executing );
   _Thread_Load_environment( executing );



More information about the vc mailing list