From e429e9742a2ca72820f8f3a8958ed138aa562bd9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 11 Nov 2021 10:34:31 +0100 Subject: score: Simplify thread wait state handling Remove the THREAD_WAIT_STATE_READY_AGAIN and simply use the initial value to indicate that a thread does not wait on something. Rename THREAD_WAIT_FLAGS_INITIAL to THREAD_WAIT_STATE_READY. This change is necessary so that _Thread_Continue() can be called for threads which never waited on something (for example dormant threads). Update #4546. --- cpukit/include/rtems/rtems/ratemonimpl.h | 3 --- cpukit/include/rtems/score/thread.h | 2 +- cpukit/include/rtems/score/threadimpl.h | 19 ++++++++----------- cpukit/rtems/src/eventsurrender.c | 12 ++++-------- cpukit/rtems/src/ratemonperiod.c | 2 +- cpukit/rtems/src/ratemontimeout.c | 4 ++-- cpukit/score/src/threadinitialize.c | 2 +- cpukit/score/src/threadqenqueue.c | 9 +++------ cpukit/score/src/threadtimeout.c | 8 +++----- 9 files changed, 23 insertions(+), 38 deletions(-) (limited to 'cpukit') diff --git a/cpukit/include/rtems/rtems/ratemonimpl.h b/cpukit/include/rtems/rtems/ratemonimpl.h index 62327c5b09..d17c7fe4de 100644 --- a/cpukit/include/rtems/rtems/ratemonimpl.h +++ b/cpukit/include/rtems/rtems/ratemonimpl.h @@ -48,9 +48,6 @@ extern "C" { #define RATE_MONOTONIC_BLOCKED \ ( THREAD_WAIT_CLASS_PERIOD | THREAD_WAIT_STATE_BLOCKED ) -#define RATE_MONOTONIC_READY_AGAIN \ - ( THREAD_WAIT_CLASS_PERIOD | THREAD_WAIT_STATE_READY_AGAIN ) - /** * @brief Allocates a period control block from * the inactive chain of free period control blocks. diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h index 23ed8e1406..c3c37eb160 100644 --- a/cpukit/include/rtems/score/thread.h +++ b/cpukit/include/rtems/score/thread.h @@ -404,7 +404,7 @@ typedef union { * The mutually exclusive wait state flags are * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK, * - @ref THREAD_WAIT_STATE_BLOCKED, and - * - @ref THREAD_WAIT_STATE_READY_AGAIN. + * - @ref THREAD_WAIT_STATE_READY. */ typedef unsigned int Thread_Wait_flags; diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index dc41d28856..a66d1a5346 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -2217,14 +2217,18 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_cancel( } /** - * @brief The initial thread wait flags value set by _Thread_Initialize(). + * @brief Mask to get the thread wait state flags. */ -#define THREAD_WAIT_FLAGS_INITIAL 0x0U +#define THREAD_WAIT_STATE_MASK 0xffU /** - * @brief Mask to get the thread wait state flags. + * @brief Indicates that the thread does not wait on something. + * + * In this wait state, the wait class is zero. This wait state is set + * initially by _Thread_Initialize() and after each wait operation once the + * thread is ready again. */ -#define THREAD_WAIT_STATE_MASK 0xffU +#define THREAD_WAIT_STATE_READY 0x0U /** * @brief Indicates that the thread begins with the blocking operation. @@ -2240,13 +2244,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_cancel( */ #define THREAD_WAIT_STATE_BLOCKED 0x2U -/** - * @brief Indicates that a condition to end the thread wait occurred. - * - * This could be a timeout, a signal, an event or a resource availability. - */ -#define THREAD_WAIT_STATE_READY_AGAIN 0x4U - /** * @brief Mask to get the thread wait class flags. */ diff --git a/cpukit/rtems/src/eventsurrender.c b/cpukit/rtems/src/eventsurrender.c index 48c08e486f..0623977c8b 100644 --- a/cpukit/rtems/src/eventsurrender.c +++ b/cpukit/rtems/src/eventsurrender.c @@ -42,12 +42,10 @@ static bool _Event_Is_blocking_on_event( ) { Thread_Wait_flags wait_flags; - Thread_Wait_flags wait_mask; wait_flags = _Thread_Wait_flags_get( the_thread ); - wait_mask = THREAD_WAIT_CLASS_MASK | THREAD_WAIT_STATE_READY_AGAIN; - return ( wait_flags & wait_mask ) == wait_class; + return ( wait_flags & THREAD_WAIT_CLASS_MASK ) == wait_class; } static bool _Event_Is_satisfied( @@ -88,16 +86,14 @@ rtems_status_code _Event_Surrender( _Event_Is_blocking_on_event( the_thread, wait_class ) && _Event_Is_satisfied( the_thread, pending_events, &seized_events ) ) { - Thread_Wait_flags ready_again; - bool success; + bool success; _Event_Satisfy( the_thread, event, pending_events, seized_events ); - ready_again = wait_class | THREAD_WAIT_STATE_READY_AGAIN; success = _Thread_Wait_flags_try_change_release( the_thread, wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK, - ready_again + THREAD_WAIT_STATE_READY ); if ( success ) { @@ -107,7 +103,7 @@ rtems_status_code _Event_Surrender( _Thread_Wait_flags_get( the_thread ) == ( wait_class | THREAD_WAIT_STATE_BLOCKED ) ); - _Thread_Wait_flags_set( the_thread, ready_again ); + _Thread_Wait_flags_set( the_thread, THREAD_WAIT_STATE_READY ); unblock = true; } } else { diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c index 32ac688a7f..a8697abf3c 100644 --- a/cpukit/rtems/src/ratemonperiod.c +++ b/cpukit/rtems/src/ratemonperiod.c @@ -247,7 +247,7 @@ static rtems_status_code _Rate_monotonic_Block_while_active( ); if ( !success ) { _Assert( - _Thread_Wait_flags_get( executing ) == RATE_MONOTONIC_READY_AGAIN + _Thread_Wait_flags_get( executing ) == THREAD_WAIT_STATE_READY ); _Thread_Unblock( executing ); } diff --git a/cpukit/rtems/src/ratemontimeout.c b/cpukit/rtems/src/ratemontimeout.c index b20e1e15db..375c5f081f 100644 --- a/cpukit/rtems/src/ratemontimeout.c +++ b/cpukit/rtems/src/ratemontimeout.c @@ -74,13 +74,13 @@ void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog ) success = _Thread_Wait_flags_try_change_release( owner, RATE_MONOTONIC_INTEND_TO_BLOCK, - RATE_MONOTONIC_READY_AGAIN + THREAD_WAIT_STATE_READY ); if ( success ) { unblock = false; } else { _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED ); - _Thread_Wait_flags_set( owner, RATE_MONOTONIC_READY_AGAIN ); + _Thread_Wait_flags_set( owner, THREAD_WAIT_STATE_READY ); unblock = true; } diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index 01ef479537..2682a9428c 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -299,7 +299,7 @@ static bool _Thread_Try_initialize( the_thread->Wait.operations = &_Thread_queue_Operations_default; the_thread->Start.initial_priority = config->priority; - RTEMS_STATIC_ASSERT( THREAD_WAIT_FLAGS_INITIAL == 0, Wait_flags ); + RTEMS_STATIC_ASSERT( THREAD_WAIT_STATE_READY == 0, Wait_flags ); /* POSIX Keys */ _RBTree_Initialize_empty( &the_thread->Keys.Key_value_pairs ); diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c index ed6c64543c..7b42cda88c 100644 --- a/cpukit/score/src/threadqenqueue.c +++ b/cpukit/score/src/threadqenqueue.c @@ -41,9 +41,6 @@ #define THREAD_QUEUE_BLOCKED \ (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_BLOCKED) -#define THREAD_QUEUE_READY_AGAIN \ - (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN) - #if defined(RTEMS_SMP) /* * A global registry of active thread queue links is used to provide deadlock @@ -560,7 +557,7 @@ static void _Thread_queue_Force_ready_again( Thread_Control *the_thread ) * We must set the wait flags under protection of the current thread lock, * otherwise a _Thread_Timeout() running on another processor may interfere. */ - _Thread_Wait_flags_set( the_thread, THREAD_QUEUE_READY_AGAIN ); + _Thread_Wait_flags_set( the_thread, THREAD_WAIT_STATE_READY ); _Thread_Wait_restore_default( the_thread ); } @@ -576,13 +573,13 @@ static bool _Thread_queue_Make_ready_again( Thread_Control *the_thread ) success = _Thread_Wait_flags_try_change_release( the_thread, THREAD_QUEUE_INTEND_TO_BLOCK, - THREAD_QUEUE_READY_AGAIN + THREAD_WAIT_STATE_READY ); if ( success ) { unblock = false; } else { _Assert( _Thread_Wait_flags_get( the_thread ) == THREAD_QUEUE_BLOCKED ); - _Thread_Wait_flags_set( the_thread, THREAD_QUEUE_READY_AGAIN ); + _Thread_Wait_flags_set( the_thread, THREAD_WAIT_STATE_READY ); unblock = true; } diff --git a/cpukit/score/src/threadtimeout.c b/cpukit/score/src/threadtimeout.c index 2f2017bebe..9431ff253d 100644 --- a/cpukit/score/src/threadtimeout.c +++ b/cpukit/score/src/threadtimeout.c @@ -35,9 +35,8 @@ void _Thread_Continue( Thread_Control *the_thread, Status_Control status ) wait_flags = _Thread_Wait_flags_get( the_thread ); - if ( ( wait_flags & THREAD_WAIT_STATE_READY_AGAIN ) == 0 ) { + if ( wait_flags != THREAD_WAIT_STATE_READY ) { Thread_Wait_flags wait_class; - Thread_Wait_flags ready_again; bool success; _Thread_Wait_cancel( the_thread, &queue_context ); @@ -45,11 +44,10 @@ void _Thread_Continue( Thread_Control *the_thread, Status_Control status ) the_thread->Wait.return_code = status; wait_class = wait_flags & THREAD_WAIT_CLASS_MASK; - ready_again = wait_class | THREAD_WAIT_STATE_READY_AGAIN; success = _Thread_Wait_flags_try_change_release( the_thread, wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK, - ready_again + THREAD_WAIT_STATE_READY ); if ( success ) { @@ -59,7 +57,7 @@ void _Thread_Continue( Thread_Control *the_thread, Status_Control status ) _Thread_Wait_flags_get( the_thread ) == ( wait_class | THREAD_WAIT_STATE_BLOCKED ) ); - _Thread_Wait_flags_set( the_thread, ready_again ); + _Thread_Wait_flags_set( the_thread, THREAD_WAIT_STATE_READY ); unblock = true; } } else { -- cgit v1.2.3