[rtems commit] rtems: Fix rtems_task_mode()

Sebastian Huber sebh at rtems.org
Thu Mar 18 09:39:38 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Mar 18 10:37:23 2021 +0100

rtems: Fix rtems_task_mode()

Do the ASR and preemption mode change only if requested by the mode
mask.  The bug was introduced by
508f868237225a75e566d9fd304206363cfe441d.

---

 cpukit/rtems/src/taskmode.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/cpukit/rtems/src/taskmode.c b/cpukit/rtems/src/taskmode.c
index 377224c..96bed47 100644
--- a/cpukit/rtems/src/taskmode.c
+++ b/cpukit/rtems/src/taskmode.c
@@ -94,31 +94,37 @@ rtems_status_code rtems_task_mode(
   if ( ( mask & ( RTEMS_ASR_MASK | RTEMS_PREEMPT_MASK ) ) != 0 ) {
     bool             need_thread_dispatch;
     ISR_lock_Context lock_context;
-    bool             previous_asr_is_enabled;
-    bool             previous_is_preemptible;
 
     need_thread_dispatch = false;
 
     _Thread_State_acquire( executing, &lock_context );
 
-    previous_asr_is_enabled = asr->is_enabled;
-    asr->is_enabled = !_Modes_Is_asr_disabled( mode_set );
+    if ( ( mask & RTEMS_ASR_MASK ) != 0 ) {
+      bool previous_asr_is_enabled;
 
-    if (
-      !previous_asr_is_enabled &&
-        asr->is_enabled &&
-        asr->signals_pending != 0
-    ) {
-      need_thread_dispatch = true;
-      _Thread_Append_post_switch_action( executing, &api->Signal_action );
+      previous_asr_is_enabled = asr->is_enabled;
+      asr->is_enabled = !_Modes_Is_asr_disabled( mode_set );
+
+      if (
+        !previous_asr_is_enabled &&
+          asr->is_enabled &&
+          asr->signals_pending != 0
+      ) {
+        need_thread_dispatch = true;
+        _Thread_Append_post_switch_action( executing, &api->Signal_action );
+      }
     }
 
-    previous_is_preemptible = executing->is_preemptible;
-    executing->is_preemptible = _Modes_Is_preempt( mode_set );
+    if ( ( mask & RTEMS_PREEMPT_MASK ) != 0 ) {
+      bool previous_is_preemptible;
+
+      previous_is_preemptible = executing->is_preemptible;
+      executing->is_preemptible = _Modes_Is_preempt( mode_set );
 
-    if ( executing->is_preemptible && !previous_is_preemptible ) {
-      need_thread_dispatch = true;
-      _Scheduler_Schedule( executing );
+      if ( executing->is_preemptible && !previous_is_preemptible ) {
+        need_thread_dispatch = true;
+        _Scheduler_Schedule( executing );
+      }
     }
 
     if ( need_thread_dispatch ) {



More information about the vc mailing list