PatchworkOS  69292a3
A non-POSIX operating system.
Loading...
Searching...
No Matches
threading.h
Go to the documentation of this file.
1#pragma once
2
3#include <errno.h>
4#include <stdatomic.h>
5#include <stdbool.h>
6#include <sys/proc.h>
7#include <threads.h>
8
9/**
10 * @brief Threading.
11 * @defgroup libstd_common_user_threading Threading
12 * @ingroup libstd_common_user
13 *
14 * @todo Write threading documentation.
15 *
16 * @todo Implement Thread Local Storage (TLS).
17 *
18 * @{
19 */
20
21#define _MTX_SPIN_COUNT 100
22
23#define _THREADS_MAX 2048
24
25typedef struct _thread _thread_t;
26
27typedef void (*_thread_entry_t)(_thread_t*);
28
29#define _THREAD_ATTACHED 1
30#define _THREAD_DETACHED 2
31#define _THREAD_JOINING 3
32#define _THREAD_EXITED 4
33
34typedef struct _thread
35{
37 atomic_uint64_t state;
39 int result;
42 void* arg;
43} _thread_t;
44
45void _threading_init(void);
46
47_thread_t* _thread_new(thrd_start_t func, void* arg);
48
49void _thread_free(_thread_t* thread);
50
52
53#define _THREAD_SELF ((_thread_t __seg_fs*)0)
54
55/** @} */
int errno_t
Definition errno_t.h:4
void _threading_init(void)
Definition threading.c:63
_thread_t * _thread_new(thrd_start_t func, void *arg)
Definition threading.c:86
_thread_t * _thread_get(tid_t id)
Definition threading.c:130
void(* _thread_entry_t)(_thread_t *)
Definition threading.h:27
void _thread_free(_thread_t *thread)
Definition threading.c:121
__UINT64_TYPE__ tid_t
Thread Identifier.
Definition tid_t.h:12
tid_t id
Definition threading.h:38
int result
Definition threading.h:39
errno_t err
Definition threading.h:40
atomic_uint64_t state
Definition threading.h:37
thrd_start_t func
Definition threading.h:41
_thread_t * self
Definition threading.h:36
void * arg
Definition threading.h:42
int(* thrd_start_t)(void *)
Definition threads.h:60