score: Rework _Thread_Restart_other()

Rework _Thread_Restart_other() to use _Thread_Change_life_locked().
Cope with concurrent change requests by means of a pending request
counter.

Update #2555.
Update #2626.
This commit is contained in:
Sebastian Huber
2016-05-20 07:49:38 +02:00
parent 9388390777
commit 862a0eeb11
4 changed files with 87 additions and 12 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ rtems_monitor_dump_priority(rtems_task_priority priority)
static const rtems_assoc_t rtems_monitor_state_assoc[] = {
{ "DELAY", STATES_DELAYING, 0 },
{ "DORM", STATES_DORMANT, 0 },
{ "RESTA", STATES_RESTARTING, 0 },
{ "LIFE", STATES_LIFE_IS_CHANGING, 0 },
{ "SUSP", STATES_SUSPENDED, 0 },
{ "Wbar", STATES_WAITING_FOR_BARRIER, 0 },
{ "Wbuf", STATES_WAITING_FOR_BUFFER, 0 },
@@ -78,8 +78,8 @@ extern "C" {
#define STATES_WAITING_FOR_BSD_WAKEUP 0x80000
/** This macro corresponds to a task being a zombie. */
#define STATES_ZOMBIE 0x200000
/** This macro corresponds to a task restarting. */
#define STATES_RESTARTING 0x800000
/** This macro corresponds to a task those life is changing. */
#define STATES_LIFE_IS_CHANGING 0x800000
/** This macro corresponds to a task waiting for a join. */
#define STATES_WAITING_FOR_JOIN 0x1000000
/** This macro corresponds to a task waiting for a <sys/lock.h> mutex. */
@@ -543,6 +543,11 @@ typedef struct {
* @brief The current thread life state.
*/
Thread_Life_state state;
/**
* @brief The count of pending life change requests.
*/
uint32_t pending_life_change_requests;
} Thread_Life_control;
#if defined(RTEMS_SMP)
+79 -9
View File
@@ -368,7 +368,7 @@ static void _Thread_Start_life_change(
the_thread->budget_algorithm = the_thread->Start.budget_algorithm;
the_thread->budget_callout = the_thread->Start.budget_callout;
_Thread_Set_state( the_thread, STATES_RESTARTING );
_Thread_Set_state( the_thread, STATES_LIFE_IS_CHANGING );
_Thread_queue_Extract_with_proxy( the_thread );
_Thread_Timer_remove( the_thread );
_Thread_Raise_real_priority( the_thread, priority );
@@ -407,6 +407,64 @@ static void _Thread_Request_life_change(
}
}
static void _Thread_Add_life_change_request( Thread_Control *the_thread )
{
uint32_t pending_requests;
_Assert( _Thread_State_is_owner( the_thread ) );
pending_requests = the_thread->Life.pending_life_change_requests;
the_thread->Life.pending_life_change_requests = pending_requests + 1;
if ( pending_requests == 0 ) {
_Thread_Set_state_locked( the_thread, STATES_LIFE_IS_CHANGING );
}
}
static void _Thread_Remove_life_change_request( Thread_Control *the_thread )
{
ISR_lock_Context lock_context;
uint32_t pending_requests;
_Thread_State_acquire( the_thread, &lock_context );
pending_requests = the_thread->Life.pending_life_change_requests;
the_thread->Life.pending_life_change_requests = pending_requests - 1;
if ( pending_requests == 1 ) {
/*
* Do not remove states used for thread queues to avoid race conditions on
* SMP configurations. We could interrupt an extract operation on another
* processor disregarding the thread wait flags. Rely on
* _Thread_queue_Extract_with_proxy() for removal of these states.
*/
_Thread_Clear_state_locked(
the_thread,
STATES_LIFE_IS_CHANGING | STATES_SUSPENDED
| ( STATES_BLOCKED & ~STATES_LOCALLY_BLOCKED )
);
}
_Thread_State_release( the_thread, &lock_context );
}
static void _Thread_Finalize_life_change(
Thread_Control *the_thread,
Priority_Control priority
)
{
_Thread_queue_Extract_with_proxy( the_thread );
_Thread_Timer_remove( the_thread );
_Thread_Change_priority(
the_thread,
priority,
NULL,
_Thread_Raise_real_priority_filter,
false
);
_Thread_Remove_life_change_request( the_thread );
}
void _Thread_Join(
Thread_Control *the_thread,
States_Control waiting_for_join,
@@ -486,7 +544,8 @@ bool _Thread_Restart_other(
ISR_lock_Context *lock_context
)
{
Per_CPU_Control *cpu_self;
Thread_Life_state previous;
Per_CPU_Control *cpu_self;
_Thread_State_acquire_critical( the_thread, lock_context );
@@ -496,16 +555,27 @@ bool _Thread_Restart_other(
}
the_thread->Start.Entry = *entry;
previous = _Thread_Change_life_locked(
the_thread,
0,
THREAD_LIFE_RESTARTING,
0
);
cpu_self = _Thread_Dispatch_disable_critical( lock_context );
_Thread_State_release( the_thread, lock_context );
_Thread_Request_life_change(
the_thread,
NULL,
the_thread->Start.initial_priority,
THREAD_LIFE_RESTARTING
);
if ( _Thread_Is_life_change_allowed( previous ) ) {
_Thread_Add_life_change_request( the_thread );
_Thread_State_release( the_thread, lock_context );
_Thread_Finalize_life_change(
the_thread,
the_thread->Start.initial_priority
);
} else {
_Thread_Clear_state_locked( the_thread, STATES_SUSPENDED );
_Thread_State_release( the_thread, lock_context );
}
_Thread_Dispatch_enable( cpu_self );
return true;