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_detach.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/libc/thread/thrd_detach.c (limited to 'lib/libc/thread/thrd_detach.c') diff --git a/lib/libc/thread/thrd_detach.c b/lib/libc/thread/thrd_detach.c new file mode 100644 index 00000000..b315a20a --- /dev/null +++ b/lib/libc/thread/thrd_detach.c @@ -0,0 +1,23 @@ +#include <__thread.h> +#include +#include +#include +#include +#include + +int thrd_detach(thrd_t thr) +{ + struct __thread_self *tcb = (struct __thread_self *)thr; + + if (tcb == NULL) + return thrd_error; + + int state = atomic_exchange_explicit(&tcb->state, THREAD_STATE_DETACHED, memory_order_seq_cst); + + if (state == THREAD_STATE_EXITED) { + if (tcb->map_base && tcb->map_size) + munmap(tcb->map_base, tcb->map_size); + } + + return thrd_success; +} -- cgit v1.2.3