2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2013-06-18 17:21:38 +02:00
|
|
|
* Copyright (C) 2013 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup core_thread
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-11-27 16:28:31 +01:00
|
|
|
* @brief Threading implementation
|
|
|
|
*
|
2014-01-28 11:50:12 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2010-09-22 15:10:42 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2021-11-25 09:20:22 +01:00
|
|
|
#include <stdalign.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
#include <stdio.h>
|
2020-07-02 08:29:49 +02:00
|
|
|
#ifdef PICOLIBC_TLS
|
|
|
|
#include <picotls.h>
|
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2015-01-17 15:17:19 +01:00
|
|
|
#include "assert.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
#include "thread.h"
|
2014-02-15 18:49:27 +01:00
|
|
|
#include "irq.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
#include "bitarithm.h"
|
2010-10-28 11:22:57 +02:00
|
|
|
#include "sched.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2020-10-22 01:02:11 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
|
|
|
#include "debug.h"
|
|
|
|
|
2024-06-04 20:21:45 +02:00
|
|
|
#if defined(HAVE_VALGRIND_H)
|
|
|
|
# include <valgrind.h>
|
|
|
|
#elif defined(HAVE_VALGRIND_VALGRIND_H)
|
|
|
|
# include <valgrind/valgrind.h>
|
|
|
|
#else
|
|
|
|
# define VALGRIND_DISABLE_ERROR_REPORTING (void)0
|
|
|
|
# define VALGRIND_ENABLE_ERROR_REPORTING (void)0
|
|
|
|
#endif
|
|
|
|
|
2019-10-15 15:48:27 +02:00
|
|
|
thread_status_t thread_getstatus(kernel_pid_t pid)
|
2014-08-13 09:26:27 +02:00
|
|
|
{
|
2020-08-06 10:46:17 +02:00
|
|
|
thread_t *thread = thread_get(pid);
|
2020-03-30 17:02:08 +02:00
|
|
|
|
2019-10-15 15:48:27 +02:00
|
|
|
return thread ? thread->status : STATUS_NOT_FOUND;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
const char *thread_getname(kernel_pid_t pid)
|
2013-10-17 15:25:43 +02:00
|
|
|
{
|
2019-11-24 16:19:48 +01:00
|
|
|
#ifdef CONFIG_THREAD_NAMES
|
2020-08-06 10:46:17 +02:00
|
|
|
thread_t *thread = thread_get(pid);
|
2019-05-11 11:39:32 +02:00
|
|
|
return thread ? thread->name : NULL;
|
2017-10-20 23:10:20 +02:00
|
|
|
#else
|
|
|
|
(void)pid;
|
|
|
|
return NULL;
|
2014-10-15 00:04:58 +02:00
|
|
|
#endif
|
2017-10-20 23:10:20 +02:00
|
|
|
}
|
2013-10-17 15:25:43 +02:00
|
|
|
|
2019-10-11 17:49:51 +02:00
|
|
|
void thread_zombify(void)
|
|
|
|
{
|
|
|
|
if (irq_is_in()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-05 18:00:13 +01:00
|
|
|
irq_disable();
|
2020-08-06 10:46:17 +02:00
|
|
|
sched_set_status(thread_get_active(), STATUS_ZOMBIE);
|
2020-02-05 18:00:13 +01:00
|
|
|
irq_enable();
|
2019-10-11 17:49:51 +02:00
|
|
|
thread_yield_higher();
|
|
|
|
|
|
|
|
/* this line should never be reached */
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
int thread_kill_zombie(kernel_pid_t pid)
|
|
|
|
{
|
|
|
|
DEBUG("thread_kill: Trying to kill PID %" PRIkernel_pid "...\n", pid);
|
|
|
|
unsigned state = irq_disable();
|
|
|
|
|
|
|
|
int result = (int)STATUS_NOT_FOUND;
|
|
|
|
|
2020-08-06 10:46:17 +02:00
|
|
|
thread_t *thread = thread_get(pid);
|
2019-10-11 17:49:51 +02:00
|
|
|
|
|
|
|
if (!thread) {
|
|
|
|
DEBUG("thread_kill: Thread does not exist!\n");
|
|
|
|
}
|
|
|
|
else if (thread->status == STATUS_ZOMBIE) {
|
|
|
|
DEBUG("thread_kill: Thread is a zombie.\n");
|
|
|
|
|
|
|
|
sched_threads[pid] = NULL;
|
|
|
|
sched_num_threads--;
|
|
|
|
sched_set_status(thread, STATUS_STOPPED);
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUG("thread_kill: Thread is not a zombie!\n");
|
|
|
|
}
|
|
|
|
irq_restore(state);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-07 12:36:32 +02:00
|
|
|
void thread_sleep(void)
|
2013-06-20 18:18:29 +02:00
|
|
|
{
|
2016-03-19 09:25:47 +01:00
|
|
|
if (irq_is_in()) {
|
2013-06-20 18:18:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned state = irq_disable();
|
2021-01-19 17:47:23 +01:00
|
|
|
|
2020-08-06 10:46:17 +02:00
|
|
|
sched_set_status(thread_get_active(), STATUS_SLEEPING);
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(state);
|
2014-10-18 01:24:49 +02:00
|
|
|
thread_yield_higher();
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
int thread_wakeup(kernel_pid_t pid)
|
2013-06-20 18:18:29 +02:00
|
|
|
{
|
2014-07-06 22:57:56 +02:00
|
|
|
DEBUG("thread_wakeup: Trying to wakeup PID %" PRIkernel_pid "...\n", pid);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned old_state = irq_disable();
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2020-08-06 10:46:17 +02:00
|
|
|
thread_t *thread = thread_get(pid);
|
2016-03-03 20:29:55 +01:00
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
if (!thread) {
|
2016-03-03 20:29:55 +01:00
|
|
|
DEBUG("thread_wakeup: Thread does not exist!\n");
|
|
|
|
}
|
2019-05-11 11:39:32 +02:00
|
|
|
else if (thread->status == STATUS_SLEEPING) {
|
2010-11-02 11:40:10 +01:00
|
|
|
DEBUG("thread_wakeup: Thread is sleeping.\n");
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
sched_set_status(thread, STATUS_RUNNING);
|
2014-02-13 23:17:36 +01:00
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(old_state);
|
2019-05-11 11:39:32 +02:00
|
|
|
sched_switch(thread->priority);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2010-11-04 16:21:39 +01:00
|
|
|
return 1;
|
2013-06-20 18:18:29 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-11-02 11:40:10 +01:00
|
|
|
DEBUG("thread_wakeup: Thread is not sleeping!\n");
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
2016-03-03 20:29:55 +01:00
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(old_state);
|
2019-02-11 14:25:46 +01:00
|
|
|
return (int)STATUS_NOT_FOUND;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2014-10-28 00:49:02 +01:00
|
|
|
void thread_yield(void)
|
|
|
|
{
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned old_state = irq_disable();
|
2020-08-06 10:46:17 +02:00
|
|
|
thread_t *me = thread_get_active();
|
2020-03-30 17:02:08 +02:00
|
|
|
|
2014-10-28 00:49:02 +01:00
|
|
|
if (me->status >= STATUS_ON_RUNQUEUE) {
|
2021-04-11 19:08:47 +02:00
|
|
|
sched_runq_advance(me->priority);
|
2014-10-28 00:49:02 +01:00
|
|
|
}
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(old_state);
|
2014-10-28 00:49:02 +01:00
|
|
|
|
|
|
|
thread_yield_higher();
|
|
|
|
}
|
|
|
|
|
2015-01-17 15:17:19 +01:00
|
|
|
void thread_add_to_list(list_node_t *list, thread_t *thread)
|
|
|
|
{
|
2020-03-30 17:02:08 +02:00
|
|
|
assert(thread->status < STATUS_ON_RUNQUEUE);
|
2015-01-17 15:17:19 +01:00
|
|
|
|
|
|
|
uint16_t my_prio = thread->priority;
|
2020-03-30 17:02:08 +02:00
|
|
|
list_node_t *new_node = (list_node_t *)&thread->rq_entry;
|
2015-01-17 15:17:19 +01:00
|
|
|
|
|
|
|
while (list->next) {
|
2020-03-30 17:02:08 +02:00
|
|
|
thread_t *list_entry = container_of((clist_node_t *)list->next,
|
|
|
|
thread_t, rq_entry);
|
2015-01-17 15:17:19 +01:00
|
|
|
if (list_entry->priority > my_prio) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_node->next = list->next;
|
|
|
|
list->next = new_node;
|
|
|
|
}
|
|
|
|
|
2024-05-31 10:59:14 +02:00
|
|
|
uintptr_t measure_stack_free_internal(const char *stack, size_t size)
|
2013-06-20 18:18:29 +02:00
|
|
|
{
|
2020-09-22 14:36:31 +02:00
|
|
|
/* Alignment of stack has been fixed (if needed) by thread_create(), so
|
|
|
|
* we can silence -Wcast-align here */
|
|
|
|
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;
|
2024-05-31 10:59:14 +02:00
|
|
|
uintptr_t end = (uintptr_t)stack + size;
|
|
|
|
|
2024-06-04 20:21:45 +02:00
|
|
|
/* HACK: This will affect native/native64 only.
|
|
|
|
*
|
|
|
|
* The dark magic used here is frowned upon by valgrind. E.g. valgrind may
|
|
|
|
* deduce that a specific value was at some point allocated on the stack,
|
|
|
|
* but has gone out of scope. When that value is now read again to
|
|
|
|
* estimate stack usage, it does look a lot like someone passed a pointer
|
|
|
|
* to a stack allocated value, and that pointer is referenced after that
|
|
|
|
* value has gone out of scope. */
|
|
|
|
VALGRIND_DISABLE_ERROR_REPORTING;
|
|
|
|
|
2014-01-20 10:42:59 +01:00
|
|
|
/* assume that the stack grows "downwards" */
|
2024-05-31 10:59:14 +02:00
|
|
|
while (((uintptr_t)stackp < end) && (*stackp == (uintptr_t)stackp)) {
|
2010-09-22 15:10:42 +02:00
|
|
|
stackp++;
|
2013-06-20 18:18:29 +02:00
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2024-06-04 20:21:45 +02:00
|
|
|
VALGRIND_ENABLE_ERROR_REPORTING;
|
|
|
|
|
2020-03-30 17:02:08 +02:00
|
|
|
uintptr_t space_free = (uintptr_t)stackp - (uintptr_t)stack;
|
2021-01-19 17:47:23 +01:00
|
|
|
|
2014-01-20 10:42:59 +01:00
|
|
|
return space_free;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 17:02:08 +02:00
|
|
|
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
|
|
|
|
int flags, thread_task_func_t function, void *arg,
|
|
|
|
const char *name)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2014-06-03 21:53:15 +02:00
|
|
|
if (priority >= SCHED_PRIO_LEVELS) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-06-06 01:55:37 +02:00
|
|
|
#ifdef DEVELHELP
|
2010-11-04 16:47:24 +01:00
|
|
|
int total_stacksize = stacksize;
|
2019-11-24 16:19:48 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_THREAD_NAMES
|
2021-01-19 17:47:23 +01:00
|
|
|
(void)name;
|
2014-06-06 01:55:37 +02:00
|
|
|
#endif
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2014-06-03 21:53:15 +02:00
|
|
|
/* align the stack on a 16/32bit boundary */
|
2021-11-25 09:20:22 +01:00
|
|
|
uintptr_t misalignment = (uintptr_t)stack % alignof(void *);
|
2014-06-03 21:53:15 +02:00
|
|
|
if (misalignment) {
|
2021-11-25 09:20:22 +01:00
|
|
|
misalignment = alignof(void *) - misalignment;
|
2014-06-03 21:53:15 +02:00
|
|
|
stack += misalignment;
|
|
|
|
stacksize -= misalignment;
|
2010-11-09 17:01:52 +01:00
|
|
|
}
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2014-06-03 21:53:15 +02:00
|
|
|
/* make room for the thread control block */
|
2016-01-04 22:29:34 +01:00
|
|
|
stacksize -= sizeof(thread_t);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2016-01-04 22:29:34 +01:00
|
|
|
/* round down the stacksize to a multiple of thread_t alignments (usually 16/32bit) */
|
2021-11-25 09:20:22 +01:00
|
|
|
stacksize -= stacksize % alignof(thread_t);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2016-03-03 20:30:09 +01:00
|
|
|
if (stacksize < 0) {
|
|
|
|
DEBUG("thread_create: stacksize is too small!\n");
|
|
|
|
}
|
2020-09-22 14:36:31 +02:00
|
|
|
/* allocate our thread control block at the top of our stackspace. Cast to
|
|
|
|
* (uintptr_t) intermediately to silence -Wcast-align. (We manually made
|
|
|
|
* sure alignment is correct above.) */
|
|
|
|
thread_t *thread = (thread_t *)(uintptr_t)(stack + stacksize);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2020-07-02 08:29:49 +02:00
|
|
|
#ifdef PICOLIBC_TLS
|
2023-03-04 10:18:36 +01:00
|
|
|
#if __PICOLIBC_MAJOR__ > 1 || __PICOLIBC_MINOR__ >= 8
|
|
|
|
#define TLS_ALIGN (alignof(thread_t) > _tls_align() ? alignof(thread_t) : _tls_align())
|
|
|
|
#else
|
|
|
|
#define TLS_ALIGN alignof(thread_t)
|
|
|
|
#endif
|
|
|
|
char *tls = stack + stacksize - _tls_size();
|
|
|
|
/*
|
|
|
|
* Make sure the TLS area is aligned as required and that the
|
|
|
|
* resulting stack will also be aligned as required
|
|
|
|
*/
|
|
|
|
thread->tls = (void *) ((uintptr_t) tls & ~ (TLS_ALIGN - 1));
|
|
|
|
stacksize = (char *) thread->tls - stack;
|
2020-07-02 08:29:49 +02:00
|
|
|
|
|
|
|
_init_tls(thread->tls);
|
|
|
|
#endif
|
|
|
|
|
2020-08-06 13:24:06 +02:00
|
|
|
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|
|
|
|
|| defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE)
|
2024-07-18 16:42:52 +02:00
|
|
|
if (flags & THREAD_CREATE_NO_STACKTEST) {
|
|
|
|
/* create stack guard. Alignment has been handled above, so silence
|
|
|
|
* -Wcast-align */
|
|
|
|
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* assign each int of the stack the value of it's address. Alignment
|
|
|
|
* has been handled above, so silence -Wcast-align */
|
|
|
|
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
|
|
|
|
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;
|
|
|
|
|
|
|
|
while (stackp < stackmax) {
|
|
|
|
*stackp = (uintptr_t)stackp;
|
|
|
|
stackp++;
|
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
2014-06-06 01:59:41 +02:00
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned state = irq_disable();
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-08-13 09:08:50 +02:00
|
|
|
kernel_pid_t pid = KERNEL_PID_UNDEF;
|
|
|
|
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; ++i) {
|
|
|
|
if (sched_threads[i] == NULL) {
|
|
|
|
pid = i;
|
2010-09-22 15:10:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-13 09:08:50 +02:00
|
|
|
if (pid == KERNEL_PID_UNDEF) {
|
2010-09-22 15:10:42 +02:00
|
|
|
DEBUG("thread_create(): too many threads!\n");
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(state);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
return -EOVERFLOW;
|
|
|
|
}
|
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
sched_threads[pid] = thread;
|
2014-08-13 09:08:50 +02:00
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->pid = pid;
|
|
|
|
thread->sp = thread_stack_init(function, arg, stack, stacksize);
|
2014-06-06 01:55:37 +02:00
|
|
|
|
2021-11-03 21:38:22 +01:00
|
|
|
#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) || \
|
2024-04-27 18:55:06 +02:00
|
|
|
defined(MODULE_MPU_STACK_GUARD) || defined(MODULE_CORTEXM_STACK_LIMIT)
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->stack_start = stack;
|
2015-09-22 17:59:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEVELHELP
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->stack_size = total_stacksize;
|
2019-11-24 16:19:48 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_THREAD_NAMES
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->name = name;
|
2014-06-06 01:55:37 +02:00
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->priority = priority;
|
|
|
|
thread->status = STATUS_STOPPED;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->rq_entry.next = NULL;
|
2010-11-26 14:21:48 +01:00
|
|
|
|
2016-02-26 22:19:31 +01:00
|
|
|
#ifdef MODULE_CORE_MSG
|
2019-05-11 11:39:32 +02:00
|
|
|
thread->wait_data = NULL;
|
|
|
|
thread->msg_waiters.next = NULL;
|
|
|
|
cib_init(&(thread->msg_queue), 0);
|
|
|
|
thread->msg_array = NULL;
|
2016-02-26 22:19:31 +01:00
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-04-10 22:28:35 +02:00
|
|
|
sched_num_threads++;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2020-03-30 17:02:08 +02:00
|
|
|
DEBUG("Created thread %s. PID: %" PRIkernel_pid ". Priority: %u.\n", name,
|
|
|
|
thread->pid, priority);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2015-12-02 11:59:20 +01:00
|
|
|
if (flags & THREAD_CREATE_SLEEPING) {
|
2019-05-11 11:39:32 +02:00
|
|
|
sched_set_status(thread, STATUS_SLEEPING);
|
2013-06-20 18:18:29 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-05-11 11:39:32 +02:00
|
|
|
sched_set_status(thread, STATUS_PENDING);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2015-12-02 11:59:20 +01:00
|
|
|
if (!(flags & THREAD_CREATE_WOUT_YIELD)) {
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(state);
|
2014-12-03 20:45:00 +01:00
|
|
|
sched_switch(priority);
|
|
|
|
return pid;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
irq_restore(state);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
return pid;
|
|
|
|
}
|
2020-11-25 14:34:03 +01:00
|
|
|
|
|
|
|
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
|
2021-01-19 17:47:23 +01:00
|
|
|
indicates that the table above is incomplete */
|
2020-11-25 14:34:03 +01:00
|
|
|
|
|
|
|
return (name != NULL) ? name : STATE_NAME_UNKNOWN;
|
|
|
|
}
|