forked from Imagelibrary/rtems
score: Add _Thread_Join() and _Thread_Cancel()
Split _Thread_Close() into _Thread_Join() and _Thread_Cancel() to prepare for a re-use in pthread_join() and pthread_cancel(). Update #2555. Update #2626.
This commit is contained in:
@@ -138,7 +138,6 @@ static const rtems_assoc_t rtems_monitor_state_assoc[] = {
|
|||||||
{ "Wslmtx", STATES_WAITING_FOR_SYS_LOCK_MUTEX, 0 },
|
{ "Wslmtx", STATES_WAITING_FOR_SYS_LOCK_MUTEX, 0 },
|
||||||
{ "Wslsem", STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE, 0 },
|
{ "Wslsem", STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE, 0 },
|
||||||
{ "Wsysev", STATES_WAITING_FOR_SYSTEM_EVENT, 0 },
|
{ "Wsysev", STATES_WAITING_FOR_SYSTEM_EVENT, 0 },
|
||||||
{ "Wterm", STATES_WAITING_FOR_TERMINATION, 0 },
|
|
||||||
{ "Wtime", STATES_WAITING_FOR_TIME, 0 },
|
{ "Wtime", STATES_WAITING_FOR_TIME, 0 },
|
||||||
{ "Wwkup", STATES_WAITING_FOR_BSD_WAKEUP, 0 },
|
{ "Wwkup", STATES_WAITING_FOR_BSD_WAKEUP, 0 },
|
||||||
{ "ZOMBI", STATES_ZOMBIE, 0 },
|
{ "ZOMBI", STATES_ZOMBIE, 0 },
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ extern "C" {
|
|||||||
#define STATES_WAITING_FOR_SYSTEM_EVENT 0x40000
|
#define STATES_WAITING_FOR_SYSTEM_EVENT 0x40000
|
||||||
/** This macro corresponds to a task waiting for BSD wakeup. */
|
/** This macro corresponds to a task waiting for BSD wakeup. */
|
||||||
#define STATES_WAITING_FOR_BSD_WAKEUP 0x80000
|
#define STATES_WAITING_FOR_BSD_WAKEUP 0x80000
|
||||||
/** This macro corresponds to a task waiting for a task termination. */
|
|
||||||
#define STATES_WAITING_FOR_TERMINATION 0x100000
|
|
||||||
/** This macro corresponds to a task being a zombie. */
|
/** This macro corresponds to a task being a zombie. */
|
||||||
#define STATES_ZOMBIE 0x200000
|
#define STATES_ZOMBIE 0x200000
|
||||||
/** This macro corresponds to a task restarting. */
|
/** This macro corresponds to a task restarting. */
|
||||||
|
|||||||
@@ -543,15 +543,6 @@ typedef struct {
|
|||||||
* @brief The current thread life state.
|
* @brief The current thread life state.
|
||||||
*/
|
*/
|
||||||
Thread_Life_state state;
|
Thread_Life_state state;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The terminator thread of this thread.
|
|
||||||
*
|
|
||||||
* In case the thread is terminated and another thread (the terminator) waits
|
|
||||||
* for the actual termination completion, then this field references the
|
|
||||||
* terminator thread.
|
|
||||||
*/
|
|
||||||
Thread_Control *terminator;
|
|
||||||
} Thread_Life_control;
|
} Thread_Life_control;
|
||||||
|
|
||||||
#if defined(RTEMS_SMP)
|
#if defined(RTEMS_SMP)
|
||||||
|
|||||||
@@ -213,6 +213,15 @@ void _Thread_Kill_zombies( void );
|
|||||||
|
|
||||||
void _Thread_Exit( Thread_Control *executing );
|
void _Thread_Exit( Thread_Control *executing );
|
||||||
|
|
||||||
|
void _Thread_Join(
|
||||||
|
Thread_Control *the_thread,
|
||||||
|
States_Control waiting_for_join,
|
||||||
|
Thread_Control *executing,
|
||||||
|
ISR_lock_Context *lock_context
|
||||||
|
);
|
||||||
|
|
||||||
|
void _Thread_Cancel( Thread_Control *the_thread, Thread_Control *executing );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Closes the thread.
|
* @brief Closes the thread.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include <rtems/score/watchdogimpl.h>
|
#include <rtems/score/watchdogimpl.h>
|
||||||
#include <rtems/score/wkspace.h>
|
#include <rtems/score/wkspace.h>
|
||||||
|
|
||||||
|
#define THREAD_JOIN_TQ_OPERATIONS &_Thread_queue_Operations_priority
|
||||||
|
|
||||||
static void _Thread_Life_action_handler(
|
static void _Thread_Life_action_handler(
|
||||||
Thread_Control *executing,
|
Thread_Control *executing,
|
||||||
Thread_Action *action,
|
Thread_Action *action,
|
||||||
@@ -84,10 +86,29 @@ static void _Thread_Raise_real_priority(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ISR_lock_Context Base;
|
||||||
|
} Thread_Join_lock_context;
|
||||||
|
|
||||||
|
static void _Thread_Wake_up_joining_threads( Thread_Control *the_thread )
|
||||||
|
{
|
||||||
|
Thread_Join_lock_context join_lock_context;
|
||||||
|
|
||||||
|
_Thread_State_acquire( the_thread, &join_lock_context.Base );
|
||||||
|
_Thread_queue_Flush_critical(
|
||||||
|
&the_thread->Join_queue.Queue,
|
||||||
|
THREAD_JOIN_TQ_OPERATIONS,
|
||||||
|
_Thread_queue_Flush_default_filter,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&join_lock_context.Base
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static void _Thread_Make_zombie( Thread_Control *the_thread )
|
static void _Thread_Make_zombie( Thread_Control *the_thread )
|
||||||
{
|
{
|
||||||
ISR_lock_Context lock_context;
|
ISR_lock_Context lock_context;
|
||||||
Thread_Zombie_control *zombies = &_Thread_Zombies;
|
Thread_Zombie_control *zombies;
|
||||||
|
|
||||||
if ( _Thread_Owns_resources( the_thread ) ) {
|
if ( _Thread_Owns_resources( the_thread ) ) {
|
||||||
_Terminate(
|
_Terminate(
|
||||||
@@ -102,10 +123,12 @@ static void _Thread_Make_zombie( Thread_Control *the_thread )
|
|||||||
&the_thread->Object
|
&the_thread->Object
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_Thread_Wake_up_joining_threads( the_thread );
|
||||||
_Thread_Set_state( the_thread, STATES_ZOMBIE );
|
_Thread_Set_state( the_thread, STATES_ZOMBIE );
|
||||||
_Thread_queue_Extract_with_proxy( the_thread );
|
_Thread_queue_Extract_with_proxy( the_thread );
|
||||||
_Thread_Timer_remove( the_thread );
|
_Thread_Timer_remove( the_thread );
|
||||||
|
|
||||||
|
zombies = &_Thread_Zombies;
|
||||||
_ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
|
_ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
|
||||||
_Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
|
_Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
|
||||||
_ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
|
_ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
|
||||||
@@ -291,13 +314,6 @@ void _Thread_Life_action_handler(
|
|||||||
if ( _Thread_Is_life_terminating( previous_life_state ) ) {
|
if ( _Thread_Is_life_terminating( previous_life_state ) ) {
|
||||||
_Thread_Make_zombie( executing );
|
_Thread_Make_zombie( executing );
|
||||||
|
|
||||||
if ( executing->Life.terminator != NULL ) {
|
|
||||||
_Thread_Clear_state(
|
|
||||||
executing->Life.terminator,
|
|
||||||
STATES_WAITING_FOR_TERMINATION
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
||||||
RTEMS_UNREACHABLE();
|
RTEMS_UNREACHABLE();
|
||||||
} else {
|
} else {
|
||||||
@@ -373,23 +389,34 @@ static void _Thread_Request_life_change(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
|
void _Thread_Join(
|
||||||
|
Thread_Control *the_thread,
|
||||||
|
States_Control waiting_for_join,
|
||||||
|
Thread_Control *executing,
|
||||||
|
ISR_lock_Context *lock_context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_Assert( the_thread != executing );
|
||||||
|
_Assert( _Thread_State_is_owner( the_thread ) );
|
||||||
|
|
||||||
|
_Thread_queue_Enqueue_critical(
|
||||||
|
&the_thread->Join_queue.Queue,
|
||||||
|
THREAD_JOIN_TQ_OPERATIONS,
|
||||||
|
executing,
|
||||||
|
waiting_for_join,
|
||||||
|
WATCHDOG_NO_TIMEOUT,
|
||||||
|
0,
|
||||||
|
lock_context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _Thread_Cancel( Thread_Control *the_thread, Thread_Control *executing )
|
||||||
{
|
{
|
||||||
_Assert( the_thread != executing );
|
_Assert( the_thread != executing );
|
||||||
|
|
||||||
if ( _States_Is_dormant( the_thread->current_state ) ) {
|
if ( _States_Is_dormant( the_thread->current_state ) ) {
|
||||||
_Thread_Make_zombie( the_thread );
|
_Thread_Make_zombie( the_thread );
|
||||||
} else {
|
} else {
|
||||||
if ( !_Thread_Is_life_terminating( executing->Life.state ) ) {
|
|
||||||
/*
|
|
||||||
* Wait for termination of victim thread. If the executing thread is
|
|
||||||
* also terminated, then do not wait. This avoids potential cyclic
|
|
||||||
* dependencies and thus dead lock.
|
|
||||||
*/
|
|
||||||
the_thread->Life.terminator = executing;
|
|
||||||
_Thread_Set_state( executing, STATES_WAITING_FOR_TERMINATION );
|
|
||||||
}
|
|
||||||
|
|
||||||
_Thread_Request_life_change(
|
_Thread_Request_life_change(
|
||||||
the_thread,
|
the_thread,
|
||||||
executing,
|
executing,
|
||||||
@@ -399,6 +426,20 @@ void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
|
||||||
|
{
|
||||||
|
ISR_lock_Context lock_context;
|
||||||
|
|
||||||
|
_Thread_State_acquire( the_thread, &lock_context );
|
||||||
|
_Thread_Join(
|
||||||
|
the_thread,
|
||||||
|
STATES_WAITING_FOR_JOIN,
|
||||||
|
executing,
|
||||||
|
&lock_context
|
||||||
|
);
|
||||||
|
_Thread_Cancel( the_thread, executing );
|
||||||
|
}
|
||||||
|
|
||||||
void _Thread_Exit( Thread_Control *executing )
|
void _Thread_Exit( Thread_Control *executing )
|
||||||
{
|
{
|
||||||
ISR_lock_Context lock_context;
|
ISR_lock_Context lock_context;
|
||||||
|
|||||||
Reference in New Issue
Block a user