guard against compilers failing to handle setjmp specially by default
[musl.git] / include / threads.h
blob52ec3100eb9e2ebf3523123ba51021582361b855
1 #ifndef _THREADS_H
2 #define _THREADS_H
4 #include <features.h>
5 #include <time.h>
7 #ifdef __cplusplus
8 extern "C" {
9 typedef unsigned long thrd_t;
10 #else
11 typedef struct __pthread *thrd_t;
12 #define thread_local _Thread_local
13 #endif
15 typedef int once_flag;
16 typedef unsigned tss_t;
17 typedef int (*thrd_start_t)(void *);
18 typedef void (*tss_dtor_t)(void *);
20 #define __NEED_cnd_t
21 #define __NEED_mtx_t
23 #include <bits/alltypes.h>
25 #define TSS_DTOR_ITERATIONS 4
27 enum {
28 thrd_success = 0,
29 thrd_busy = 1,
30 thrd_error = 2,
31 thrd_nomem = 3,
32 thrd_timedout = 4,
35 enum {
36 mtx_plain = 0,
37 mtx_recursive = 1,
38 mtx_timed = 2,
41 #define ONCE_FLAG_INIT 0
43 int thrd_create(thrd_t *, thrd_start_t, void *);
44 _Noreturn void thrd_exit(int);
46 int thrd_detach(thrd_t);
47 int thrd_join(thrd_t, int *);
49 int thrd_sleep(const struct timespec *, struct timespec *);
50 void thrd_yield(void);
52 thrd_t thrd_current(void);
53 int thrd_equal(thrd_t, thrd_t);
54 #ifndef __cplusplus
55 #define thrd_equal(A, B) ((A) == (B))
56 #endif
58 void call_once(once_flag *, void (*)(void));
60 int mtx_init(mtx_t *, int);
61 void mtx_destroy(mtx_t *);
63 int mtx_lock(mtx_t *);
64 int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
65 int mtx_trylock(mtx_t *);
66 int mtx_unlock(mtx_t *);
68 int cnd_init(cnd_t *);
69 void cnd_destroy(cnd_t *);
71 int cnd_broadcast(cnd_t *);
72 int cnd_signal(cnd_t *);
74 int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict);
75 int cnd_wait(cnd_t *, mtx_t *);
77 int tss_create(tss_t *, tss_dtor_t);
78 void tss_delete(tss_t);
80 int tss_set(tss_t, void *);
81 void *tss_get(tss_t);
83 #if _REDIR_TIME64
84 __REDIR(thrd_sleep, __thrd_sleep_time64);
85 __REDIR(mtx_timedlock, __mtx_timedlock_time64);
86 __REDIR(cnd_timedwait, __cnd_timedwait_time64);
87 #endif
89 #ifdef __cplusplus
91 #endif
93 #endif