mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core: thread: move thread_state_to_string() from ps.c
This commit is contained in:
parent
09defe017f
commit
5321bcde89
@ -588,6 +588,14 @@ static inline int thread_has_msg_queue(const volatile struct _thread *thread)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a thread state code to a human readable string.
|
||||
*
|
||||
* @param state thread state to convert
|
||||
* @returns ptr to string representation of thread state (or to "unknown")
|
||||
*/
|
||||
const char *thread_state_to_string(thread_status_t state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -318,3 +318,31 @@ 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(name != NULL); /* if compiling with assertions, this is an error that
|
||||
indicates that the table above is incomplete */
|
||||
|
||||
return (name != NULL) ? name : STATE_NAME_UNKNOWN;
|
||||
}
|
||||
|
41
sys/ps/ps.c
41
sys/ps/ps.c
@ -32,45 +32,6 @@
|
||||
#include "tlsf-malloc.h"
|
||||
#endif
|
||||
|
||||
/* list of states copied from tcb.h */
|
||||
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"
|
||||
|
||||
/**
|
||||
* Convert a thread state code to a human readable string.
|
||||
*
|
||||
* This function should be used instead of a direct array lookup: if ever
|
||||
* state_names and the actual states in tcb.h get out of sync, a hole will be
|
||||
* left in the lookup table. If compiling with NDEBUG not defined, this will
|
||||
* generate an assertion which should make it clear that the table needs
|
||||
* updating. With NDEBUG, any missing code will result in the string "unknown"
|
||||
* (while direct access would return a NULL, possibly causing a crash.)
|
||||
*/
|
||||
static const char *state_to_string(thread_status_t state)
|
||||
{
|
||||
const char *name = state_names[state] ? state_names[state] : NULL;
|
||||
|
||||
assert(name != NULL); /* if compiling with assertions, this is an error that
|
||||
indicates that the table above is incomplete */
|
||||
|
||||
return (name != NULL) ? name : STATE_NAME_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prints a list of running threads including stack usage to stdout.
|
||||
*/
|
||||
@ -127,7 +88,7 @@ void ps(void)
|
||||
|
||||
if (p != NULL) {
|
||||
thread_status_t state = p->status; /* copy state */
|
||||
const char *sname = state_to_string(state); /* get state name */
|
||||
const char *sname = thread_state_to_string(state); /* get state name */
|
||||
const char *queued = &queued_name[(int)(state >= STATUS_ON_RUNQUEUE)]; /* get queued flag */
|
||||
#ifdef DEVELHELP
|
||||
int stacksz = p->stack_size; /* get stack size */
|
||||
|
Loading…
Reference in New Issue
Block a user