PatchworkOS
Loading...
Searching...
No Matches
thrd_exit.c
Go to the documentation of this file.
1#include <stdatomic.h>
2#include <stdbool.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <sys/proc.h>
6#include <threads.h>
7
10
11void thrd_exit(int res)
12{
13 _thread_t* thread = _thread_get(gettid());
14 if (thread == NULL)
15 {
16 fprintf(stderr, "libstd: thrd_exit called from unknown thread\n");
17 abort();
18 }
19
20 thread->result = res;
21
23 if (state == _THREAD_DETACHED)
24 {
25 _thread_free(thread);
26 }
27 else
28 {
30 }
31
33}
#define CLOCKS_NEVER
Definition clock_t.h:16
tid_t gettid(void)
System call to retrieve the current tid.
Definition gettid.c:6
uint64_t futex(atomic_uint64_t *addr, uint64_t val, futex_op_t op, clock_t timeout)
System call for fast user space mutual exclusion.
Definition futex.c:6
#define FUTEX_ALL
Futex wake all constant.
Definition proc.h:238
@ FUTEX_WAKE
The futex operation for waking up a amount of threads specified by the val argument.
Definition proc.h:228
#define NULL
Pointer error value.
Definition NULL.h:23
_thread_t * _thread_get(tid_t id)
Definition thread.c:72
void _thread_free(_thread_t *thread)
Definition thread.c:61
static _NORETURN void _syscall_thread_exit(void)
Definition syscalls.h:99
#define _THREAD_EXITED
Definition thread.h:21
#define _THREAD_DETACHED
Definition thread.h:19
#define atomic_exchange(object, desired)
Definition stdatomic.h:282
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
FILE * stderr
Definition std_streams.c:18
_PUBLIC int fprintf(FILE *_RESTRICT stream, const char *_RESTRICT format,...)
Definition fprintf.c:5
_PUBLIC _NORETURN void abort(void)
Definition abort.c:7
int result
Definition thread.h:28
atomic_uint64_t state
Definition thread.h:26
void thrd_exit(int res)
Definition thrd_exit.c:11