diff --git a/core/include/sched.h b/core/include/sched.h index 49b4c35eef..a9e89a099d 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -155,10 +155,7 @@ static inline int pid_is_valid(kernel_pid_t pid) typedef struct _thread thread_t; /** - * @name Thread states supported by RIOT - * - * Keep in sync with OpenOCD src/rtos/riot.c - * @{ + * @brief Thread states supported by RIOT */ typedef enum { STATUS_STOPPED, /**< has terminated */ @@ -176,7 +173,14 @@ typedef enum { STATUS_PENDING, /**< waiting to be scheduled to run */ STATUS_NUMOF /**< number of supported thread states */ } thread_status_t; -/** @} */ + +/** + * @brief List of thread state names + * + * This is a look up table for @ref thread_status_t used by OpenOCD and to + * implement @ref thread_state_to_string + */ +extern const char * const * const thread_state_names; /** * @name Helpers to work with thread states diff --git a/core/sched.c b/core/sched.c index fb8dbc3d7c..25a77edf33 100644 --- a/core/sched.c +++ b/core/sched.c @@ -67,6 +67,27 @@ const uint8_t max_threads = ARRAY_SIZE(sched_threads); FORCE_USED_SECTION const uint8_t _tcb_name_offset = offsetof(thread_t, name); #endif + +FORCE_USED_SECTION +static const char * const _thread_state_names[STATUS_NUMOF] = { + [STATUS_STOPPED] = "stopped", + [STATUS_ZOMBIE] = "zombie", + [STATUS_SLEEPING] = "sleeping", + [STATUS_MUTEX_BLOCKED] = "bl mutex", + [STATUS_RECEIVE_BLOCKED] = "bl rx", + [STATUS_SEND_BLOCKED] = "bl send", + [STATUS_REPLY_BLOCKED] = "bl reply", + [STATUS_FLAG_BLOCKED_ANY] = "bl anyfl", + [STATUS_FLAG_BLOCKED_ALL] = "bl allfl", + [STATUS_MBOX_BLOCKED] = "bl mbox", + [STATUS_COND_BLOCKED] = "bl cond", + [STATUS_RUNNING] = "running", + [STATUS_PENDING] = "pending", +}; +FORCE_USED_SECTION +const char * const * const thread_state_names = _thread_state_names; +FORCE_USED_SECTION +const uint8_t thread_state_names_numof = ARRAY_SIZE(_thread_state_names); /** @} */ volatile thread_t *sched_active_thread; diff --git a/core/thread.c b/core/thread.c index 430130d761..cad91c6775 100644 --- a/core/thread.c +++ b/core/thread.c @@ -321,27 +321,12 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, return pid; } -static const char *state_names[STATUS_NUMOF] = { - [STATUS_STOPPED] = "stopped", - [STATUS_ZOMBIE] = "zombie", - [STATUS_SLEEPING] = "sleeping", - [STATUS_MUTEX_BLOCKED] = "bl mutex", - [STATUS_RECEIVE_BLOCKED] = "bl rx", - [STATUS_SEND_BLOCKED] = "bl send", - [STATUS_REPLY_BLOCKED] = "bl reply", - [STATUS_FLAG_BLOCKED_ANY] = "bl anyfl", - [STATUS_FLAG_BLOCKED_ALL] = "bl allfl", - [STATUS_MBOX_BLOCKED] = "bl mbox", - [STATUS_COND_BLOCKED] = "bl cond", - [STATUS_RUNNING] = "running", - [STATUS_PENDING] = "pending", -}; - #define STATE_NAME_UNKNOWN "unknown" const char *thread_state_to_string(thread_status_t state) { - const char *name = state_names[state] ? state_names[state] : NULL; + assert((unsigned)state < STATUS_NUMOF); + const char *name = thread_state_names[state]; assert(name != NULL); /* if compiling with assertions, this is an error that indicates that the table above is incomplete */