From 0f30d227497418c6d3bef7d52244407e30454504 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 22 Dec 2025 23:27:56 +0100 Subject: Added c11 threads, fixed some locks and add *_unlocked functions --- lib/libc/thread/thrd_exit.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/libc/thread/thrd_exit.c (limited to 'lib/libc/thread/thrd_exit.c') diff --git a/lib/libc/thread/thrd_exit.c b/lib/libc/thread/thrd_exit.c new file mode 100644 index 00000000..9ba1f54a --- /dev/null +++ b/lib/libc/thread/thrd_exit.c @@ -0,0 +1,25 @@ +#include <__thread.h> +#include +#include +#include +#include +#include + +_Noreturn void thrd_exit(int res) +{ + struct __thread_self *self = thrd_current(); + + self->res = res; + + int state = atomic_load_explicit((int *)&self->state, memory_order_seq_cst); + if (state == THREAD_STATE_DETACHED) { + if (self->map_base && self->map_size) + munmap(self->map_base, self->map_size); + _exit(0); + } + + atomic_store_explicit(&self->state, THREAD_STATE_EXITED, memory_order_seq_cst); + __futex_wake(&self->state, 1); + + _exit(0); +} -- cgit v1.2.3