PatchworkOS  19e446b
A non-POSIX operating system.
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_SELF->self;
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:18
#define _THREAD_EXITED
Definition threading.h:32
#define _THREAD_SELF
Definition threading.h:53
#define _THREAD_DETACHED
Definition threading.h:30
void _thread_free(_thread_t *thread)
Definition threading.c:121
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:203
@ FUTEX_WAKE
Wake up one or more threads waiting on the futex.
Definition proc.h:193
#define NULL
Pointer error value.
Definition NULL.h:25
#define atomic_exchange(object, desired)
Definition stdatomic.h:282
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
FILE * stderr
Definition std_streams.c:19
_PUBLIC int fprintf(FILE *_RESTRICT stream, const char *_RESTRICT format,...)
Definition fprintf.c:3
_PUBLIC _NORETURN void abort(void)
Definition abort.c:9
int result
Definition threading.h:39
atomic_uint64_t state
Definition threading.h:37
_thread_t * self
Definition threading.h:36
static _NORETURN void _syscall_thread_exit(void)
Definition syscalls.h:90
void thrd_exit(int res)
Definition thrd_exit.c:11