From ff2e6c647d166fa54769f3c300855ef7f8020668 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 2 Aug 2016 11:26:56 +0200 Subject: score: Fix and simplify thread wait locks There was a subtile race condition in _Thread_queue_Do_extract_locked(). It must first update the thread wait flags and then restore the default thread wait state. In the previous implementation this could lead under rare timing conditions to an ineffective _Thread_Wait_tranquilize() resulting to a corrupt system state. Update #2556. --- cpukit/score/include/rtems/score/threadqimpl.h | 112 ++----------------------- 1 file changed, 6 insertions(+), 106 deletions(-) (limited to 'cpukit/score/include/rtems/score/threadqimpl.h') diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h index f0ca614ba1..75ef4dd87e 100644 --- a/cpukit/score/include/rtems/score/threadqimpl.h +++ b/cpukit/score/include/rtems/score/threadqimpl.h @@ -234,115 +234,19 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_MP_callout( } while ( 0 ) #endif -/** - * @brief Gets the thread wait queue of the thread queue context. - * - * On SMP configurations, the value is stored in the thread queue context, - * otherwise in the thread itself. - * - * @param queue_context The thread queue context. - * @param the_thread The thread. - */ -#if defined(RTEMS_SMP) -#define _Thread_queue_Context_get_queue( queue_context, the_thread ) \ - ( queue_context )->Wait.queue -#else -#define _Thread_queue_Context_get_queue( queue_context, the_thread ) \ - ( the_thread )->Wait.queue -#endif - -/** - * @brief Gets the thread wait operations of the thread queue context. - * - * On SMP configurations, the value is stored in the thread queue context, - * otherwise in the thread itself. - * - * @param queue_context The thread queue context. - * @param the_thread The thread. - */ -#if defined(RTEMS_SMP) -#define _Thread_queue_Context_get_operations( queue_context, the_thread ) \ - ( queue_context )->Wait.operations -#else -#define _Thread_queue_Context_get_operations( queue_context, the_thread ) \ - ( the_thread )->Wait.operations -#endif - -/** - * @brief Thread priority change by means of the thread queue context. - * - * On SMP configurations, the used data is stored in the thread queue context, - * otherwise in the thread itself. - * - * @param queue_context The thread queue context. - * @param the_thread The thread. - * @param new_priority The new thread priority. - * @param prepend_it Prepend it to its priority group or not. - */ -#if defined(RTEMS_SMP) -#define _Thread_queue_Context_priority_change( \ - queue_context, \ - the_thread, \ - new_priority, \ - prepend_it \ - ) \ - ( *( queue_context )->Wait.operations->priority_change )( \ - the_thread, \ - new_priority, \ - prepend_it, \ - ( queue_context )->Wait.queue \ - ) -#else -#define _Thread_queue_Context_priority_change( \ - queue_context, \ - the_thread, \ - new_priority, \ - prepend_it \ - ) \ - ( *( the_thread )->Wait.operations->priority_change )( \ - the_thread, \ - new_priority, \ - prepend_it, \ - ( the_thread )->Wait.queue \ - ) -#endif - -/** - * @brief Thread queue extract by means of the thread queue context. - * - * On SMP configurations, the used data is stored in the thread queue context, - * otherwise in the thread itself. - * - * @param queue_context The thread queue context. - * @param the_thread The thread. - */ #if defined(RTEMS_SMP) -#define _Thread_queue_Context_extract( \ - queue_context, \ - the_thread \ - ) \ - ( *( queue_context )->Wait.operations->extract )( \ - ( queue_context )->Wait.queue, \ - the_thread \ - ) -#else -#define _Thread_queue_Context_extract( \ - queue_context, \ - the_thread \ - ) \ - ( *( the_thread )->Wait.operations->extract )( \ - ( the_thread )->Wait.queue, \ - the_thread \ - ) -#endif +RTEMS_INLINE_ROUTINE void _Thread_queue_Gate_close( + Thread_queue_Gate *gate +) +{ + _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED ); +} -#if defined(RTEMS_SMP) RTEMS_INLINE_ROUTINE void _Thread_queue_Gate_add( Chain_Control *chain, Thread_queue_Gate *gate ) { - _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED ); _Chain_Append_unprotected( chain, &gate->Node ); } @@ -1087,10 +991,6 @@ extern const Thread_queue_Operations _Thread_queue_Operations_priority; extern const Thread_queue_Operations _Thread_queue_Operations_priority_inherit; -#if defined(RTEMS_SMP) -extern const Thread_queue_Operations _Thread_queue_Operations_stale_queue; -#endif - /**@}*/ #ifdef __cplusplus -- cgit v1.2.3