[PATCH 2/5] mpci: Fix thread queue flush method

Sebastian Huber sebastian.huber at embedded-brains.de
Tue May 24 12:07:12 UTC 2016


We must call the MP callout for proxies if we unblock them after a
thread queue extraction.  This was missing in
_Thread_queue_Flush_critical().  Move thread remove timer and unblock
code to new function _Thread_Remove_timer_and_unblock().
---
 cpukit/score/include/rtems/score/threadimpl.h  | 19 ++++++++
 cpukit/score/include/rtems/score/threadqimpl.h | 60 +++++------------------
 cpukit/score/src/coremutexsurrender.c          |  2 -
 cpukit/score/src/mutex.c                       |  2 -
 cpukit/score/src/threadqenqueue.c              | 67 ++++++++++----------------
 cpukit/score/src/threadqflush.c                |  3 +-
 6 files changed, 56 insertions(+), 97 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index c2ed6ee..0802730 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -1571,6 +1571,25 @@ RTEMS_INLINE_ROUTINE void _Thread_Timer_remove( Thread_Control *the_thread )
   _ISR_lock_Release_and_ISR_enable( &the_thread->Timer.Lock, &lock_context );
 }
 
+RTEMS_INLINE_ROUTINE void _Thread_Remove_timer_and_unblock(
+  Thread_Control     *the_thread,
+  Thread_queue_Queue *queue
+)
+{
+  _Thread_Timer_remove( the_thread );
+
+#if defined(RTEMS_MULTIPROCESSING)
+  if ( _Objects_Is_local_id( the_thread->Object.id ) ) {
+    _Thread_Unblock( the_thread );
+  } else {
+    _Thread_queue_Unblock_proxy( queue, the_thread );
+  }
+#else
+  (void) queue;
+  _Thread_Unblock( the_thread );
+#endif
+}
+
 RTEMS_INLINE_ROUTINE void _Thread_Debug_set_real_processor(
   Thread_Control  *the_thread,
   Per_CPU_Control *cpu
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 5ce89e7..0c4e979 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -407,17 +407,6 @@ bool _Thread_queue_Do_extract_locked(
     )
 #endif
 
-void _Thread_queue_Do_unblock_critical(
-  bool                     unblock,
-  Thread_queue_Queue      *queue,
-  Thread_Control          *the_thread,
-#if defined(RTEMS_MULTIPROCESSING)
-  Thread_queue_MP_callout  mp_callout,
-  Objects_Id               mp_id,
-#endif
-  ISR_lock_Context        *lock_context
-);
-
 /**
  * @brief Unblocks the thread which was on the thread queue before.
  *
@@ -430,46 +419,14 @@ void _Thread_queue_Do_unblock_critical(
  * _Thread_queue_Extract_locked().
  * @param[in] queue The actual thread queue.
  * @param[in] the_thread The thread to extract.
- * @param[in] mp_callout Callout to unblock the thread in case it is actually a
- *   thread proxy.  This parameter is only used on multiprocessing
- *   configurations.
- * @param[in] mp_id Object identifier of the object containing the thread
- *   queue.  This parameter is only used on multiprocessing configurations.
  * @param[in] lock_context The lock context of the lock acquire.
  */
-#if defined(RTEMS_MULTIPROCESSING)
-  #define _Thread_queue_Unblock_critical( \
-    unblock, \
-    queue, \
-    the_thread, \
-    mp_callout, \
-    mp_id, \
-    lock_context \
-  ) \
-    _Thread_queue_Do_unblock_critical( \
-      unblock, \
-      queue, \
-      the_thread, \
-      mp_callout, \
-      mp_id, \
-      lock_context \
-    )
-#else
-  #define _Thread_queue_Unblock_critical( \
-    unblock, \
-    queue, \
-    the_thread, \
-    mp_callout, \
-    mp_id, \
-    lock_context \
-  ) \
-    _Thread_queue_Do_unblock_critical( \
-      unblock, \
-      queue, \
-      the_thread, \
-      lock_context \
-    )
-#endif
+void _Thread_queue_Unblock_critical(
+  bool                unblock,
+  Thread_queue_Queue *queue,
+  Thread_Control     *the_thread,
+  ISR_lock_Context   *lock_context
+);
 
 void _Thread_queue_Do_extract_critical(
   Thread_queue_Queue            *queue,
@@ -831,6 +788,11 @@ void _Thread_queue_MP_callout_do_nothing(
   Thread_Control *the_proxy,
   Objects_Id      mp_id
 );
+
+void _Thread_queue_Unblock_proxy(
+  Thread_queue_Queue *queue,
+  Thread_Control     *the_thread
+);
 #endif
 
 extern const Thread_queue_Operations _Thread_queue_Operations_default;
diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c
index cf6f096..6fcbc43 100644
--- a/cpukit/score/src/coremutexsurrender.c
+++ b/cpukit/score/src/coremutexsurrender.c
@@ -157,8 +157,6 @@ CORE_mutex_Status _CORE_mutex_Do_surrender(
       unblock,
       &the_mutex->Wait_queue.Queue,
       the_thread,
-      mp_callout,
-      mp_id,
       lock_context
     );
   } else {
diff --git a/cpukit/score/src/mutex.c b/cpukit/score/src/mutex.c
index 5588926..b28964d 100644
--- a/cpukit/score/src/mutex.c
+++ b/cpukit/score/src/mutex.c
@@ -154,8 +154,6 @@ static void _Mutex_Release_slow(
       unblock,
       &mutex->Queue.Queue,
       first,
-      NULL,
-      0,
       lock_context
     );
   } else {
diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c
index ce72008..84de11e 100644
--- a/cpukit/score/src/threadqenqueue.c
+++ b/cpukit/score/src/threadqenqueue.c
@@ -87,25 +87,7 @@ void _Thread_queue_Enqueue_critical(
     THREAD_QUEUE_BLOCKED
   );
   if ( !success ) {
-    _Thread_Timer_remove( the_thread );
-
-#if defined(RTEMS_MULTIPROCESSING)
-    if ( _Objects_Is_local_id( the_thread->Object.id ) ) {
-      _Thread_Unblock( the_thread );
-    } else {
-      Thread_Proxy_control *the_proxy;
-
-      the_proxy = (Thread_Proxy_control *) the_thread;
-      ( *the_proxy->thread_queue_callout )(
-        the_thread,
-        the_proxy->thread_queue_id
-      );
-
-      _Thread_MP_Free_proxy( the_thread );
-    }
-#else
-    _Thread_Unblock( the_thread );
-#endif
+    _Thread_Remove_timer_and_unblock( the_thread, queue );
   }
 
   _Thread_Dispatch_enable( cpu_self );
@@ -163,15 +145,11 @@ bool _Thread_queue_Do_extract_locked(
   return unblock;
 }
 
-void _Thread_queue_Do_unblock_critical(
-  bool                     unblock,
-  Thread_queue_Queue      *queue,
-  Thread_Control          *the_thread,
-#if defined(RTEMS_MULTIPROCESSING)
-  Thread_queue_MP_callout  mp_callout,
-  Objects_Id               mp_id,
-#endif
-  ISR_lock_Context        *lock_context
+void _Thread_queue_Unblock_critical(
+  bool                unblock,
+  Thread_queue_Queue *queue,
+  Thread_Control     *the_thread,
+  ISR_lock_Context   *lock_context
 )
 {
   if ( unblock ) {
@@ -180,18 +158,7 @@ void _Thread_queue_Do_unblock_critical(
     cpu_self = _Thread_Dispatch_disable_critical( lock_context );
     _Thread_queue_Queue_release( queue, lock_context );
 
-    _Thread_Timer_remove( the_thread );
-
-#if defined(RTEMS_MULTIPROCESSING)
-    if ( _Objects_Is_local_id( the_thread->Object.id ) ) {
-      _Thread_Unblock( the_thread );
-    } else {
-      ( *mp_callout )( the_thread, mp_id );
-      _Thread_MP_Free_proxy( the_thread );
-    }
-#else
-    _Thread_Unblock( the_thread );
-#endif
+    _Thread_Remove_timer_and_unblock( the_thread, queue );
 
     _Thread_Dispatch_enable( cpu_self );
   } else {
@@ -224,8 +191,6 @@ void _Thread_queue_Do_extract_critical(
     unblock,
     queue,
     the_thread,
-    mp_callout,
-    mp_id,
     lock_context
   );
 }
@@ -290,3 +255,21 @@ Thread_Control *_Thread_queue_Do_dequeue(
 
   return the_thread;
 }
+
+#if defined(RTEMS_MULTIPROCESSING)
+void _Thread_queue_Unblock_proxy(
+  Thread_queue_Queue *queue,
+  Thread_Control     *the_thread
+)
+{
+  Thread_Proxy_control *the_proxy;
+
+  the_proxy = (Thread_Proxy_control *) the_thread;
+  ( *the_proxy->thread_queue_callout )(
+    the_thread,
+    the_proxy->thread_queue_id
+  );
+
+  _Thread_MP_Free_proxy( the_thread );
+}
+#endif
diff --git a/cpukit/score/src/threadqflush.c b/cpukit/score/src/threadqflush.c
index 9e54e1f..a67f354 100644
--- a/cpukit/score/src/threadqflush.c
+++ b/cpukit/score/src/threadqflush.c
@@ -95,8 +95,7 @@ size_t _Thread_queue_Do_flush_critical(
 
       next = _Chain_Next( node );
       the_thread = THREAD_CHAIN_NODE_TO_THREAD( node );
-      _Thread_Timer_remove( the_thread );
-      _Thread_Unblock( the_thread );
+      _Thread_Remove_timer_and_unblock( the_thread, queue );
 
       node = next;
     } while ( node != tail );
-- 
1.8.4.5




More information about the devel mailing list