1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

core/thread.c: new function for zombie state

This commit is contained in:
JulianHolzwarth 2019-10-11 17:49:51 +02:00
parent 6b0156eac5
commit 2655c97fd5
2 changed files with 64 additions and 0 deletions

View File

@ -398,6 +398,27 @@ void thread_yield(void);
*/
void thread_yield_higher(void);
/**
* @brief Puts the current thread into zombie state.
*
* @details Does nothing when in ISR.
* A thread in zombie state will never be scheduled again,
* but its scheduler entry and stack will be kept.
* A zombie state thread is supposed to be cleaned up
* by @ref thread_kill_zombie().
*/
void thread_zombify(void);
/**
* @brief Terminates zombie thread.
*
* @param[in] pid the PID of the thread to terminate
*
* @return `1` on success
* @return `STATUS_NOT_FOUND` if pid is unknown or not a zombie
*/
int thread_kill_zombie(kernel_pid_t pid);
/**
* @brief Wakes up a sleeping thread.
*

View File

@ -55,6 +55,49 @@ const char *thread_getname(kernel_pid_t pid)
#endif
}
void thread_zombify(void)
{
if (irq_is_in()) {
return;
}
unsigned state = irq_disable();
sched_set_status((thread_t *)sched_active_thread, STATUS_ZOMBIE);
irq_restore(state);
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;
thread_t *thread = (thread_t *) thread_get(pid);
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;
}
void thread_sleep(void)
{
if (irq_is_in()) {