diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-25 10:54:49 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-31 08:29:43 +0200 |
commit | 1b1be254e7a3e3d6fe6d55d62010a81a7ef35411 (patch) | |
tree | c8bacf15b0f092728fd69debcb2387b65db33ed0 /cpukit/score/include/rtems/score/thread.h | |
parent | score: Replace _Thread_Reset() (diff) | |
download | rtems-1b1be254e7a3e3d6fe6d55d62010a81a7ef35411.tar.bz2 |
score: Thread life cycle re-implementation
The thread deletion is now supported on SMP.
This change fixes the following PRs:
PR1814: SMP race condition between stack free and dispatch
PR2035: psxcancel reveals NULL pointer access in _Thread_queue_Extract()
The POSIX cleanup handler are now called in the right context (should be
called in the context of the terminating thread).
http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html
Add a user extension the reflects a thread termination event. This is
used to reclaim the Newlib reentrancy structure (may use file
operations), the POSIX cleanup handlers and the POSIX key destructors.
Diffstat (limited to 'cpukit/score/include/rtems/score/thread.h')
-rw-r--r-- | cpukit/score/include/rtems/score/thread.h | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h index d853aa035a..31fbbfa7d4 100644 --- a/cpukit/score/include/rtems/score/thread.h +++ b/cpukit/score/include/rtems/score/thread.h @@ -11,6 +11,8 @@ * COPYRIGHT (c) 1989-2014. * On-Line Applications Research Corporation (OAR). * + * Copyright (c) 2014 embedded brains GmbH. + * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. @@ -396,8 +398,47 @@ typedef struct { Chain_Control Chain; } Thread_Action_control; +/** + * @brief Thread life states. + * + * The thread life states are orthogonal to the thread states used for + * synchronization primitives and blocking operations. They reflect the state + * changes triggered with thread restart and delete requests. + */ +typedef enum { + THREAD_LIFE_NORMAL = 0x0, + THREAD_LIFE_PROTECTED = 0x1, + THREAD_LIFE_RESTARTING = 0x2, + THREAD_LIFE_PROTECTED_RESTARTING = 0x3, + THREAD_LIFE_TERMINATING = 0x4, + THREAD_LIFE_PROTECTED_TERMINATING = 0x5, + THREAD_LIFE_RESTARTING_TERMINTING = 0x6, + THREAD_LIFE_PROTECTED_RESTARTING_TERMINTING = 0x7 +} Thread_Life_state; + +/** + * @brief Thread life control. + */ typedef struct { + /** + * @brief Thread life action used to react upon thread restart and delete + * requests. + */ Thread_Action Action; + + /** + * @brief The current thread life 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; /** @@ -470,9 +511,10 @@ struct Thread_Control_struct { * thread and thread dispatching is necessary. On SMP a thread dispatch on a * remote processor needs help from an inter-processor interrupt, thus it * will take some time to complete the state change. A lot of things can - * happen in the meantime. + * happen in the meantime. This field is volatile since it is polled in + * _Thread_Kill_zombies(). */ - bool is_executing; + volatile bool is_executing; #if __RTEMS_HAVE_SYS_CPUSET_H__ /** |