1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/hashmap.hpp>
6#include <mos/tasks/task_types.hpp>
7#include <mos/types.h>
8
9typedef struct _hashmap hashmap_t;
10
11extern mos::HashMap<tid_t, Thread *> thread_table;
12
13should_inline bool thread_is_valid(const Thread *thread)
14{
15 if (auto ptr = thread)
16 return ptr->magic == THREAD_MAGIC_THRD;
17 else
18 return false;
19}
20
21Thread *thread_allocate(Process *owner, thread_mode tflags);
22void thread_destroy(Thread *thread);
23
24PtrResult<Thread> thread_new(Process *owner, thread_mode mode, mos::string_view name, size_t stack_size, void *stack);
25Thread *thread_complete_init(Thread *thread);
26Thread *thread_get(tid_t id);
27bool thread_wait_for_tid(tid_t tid);
28
29[[noreturn]] void thread_exit(Thread *&&t);
30[[noreturn]] void thread_exit_locked(Thread *&&t);
31