OLD | NEW |
1 #ifndef _THREADS_H | 1 #ifndef _THREADS_H |
2 #define _THREADS_H | 2 #define _THREADS_H |
3 | 3 |
4 #include <features.h> | 4 #include <features.h> |
5 #include <time.h> | 5 #include <time.h> |
6 | 6 |
7 #ifdef __cplusplus | 7 #ifdef __cplusplus |
8 extern "C" { | 8 extern "C" { |
9 typedef unsigned long thrd_t; | 9 typedef unsigned long thrd_t; |
10 #else | 10 #else |
11 typedef struct __pthread *thrd_t; | 11 typedef struct __pthread* thrd_t; |
12 #define thread_local _Thread_local | 12 #define thread_local _Thread_local |
13 #endif | 13 #endif |
14 | 14 |
15 typedef int once_flag; | 15 typedef int once_flag; |
16 typedef unsigned tss_t; | 16 typedef unsigned tss_t; |
17 typedef int (*thrd_start_t)(void *); | 17 typedef int (*thrd_start_t)(void*); |
18 typedef void (*tss_dtor_t)(void *); | 18 typedef void (*tss_dtor_t)(void*); |
19 | 19 |
20 #define __NEED_cnd_t | 20 #define __NEED_cnd_t |
21 #define __NEED_mtx_t | 21 #define __NEED_mtx_t |
22 | 22 |
23 #include <bits/alltypes.h> | 23 #include <bits/alltypes.h> |
24 | 24 |
25 #define TSS_DTOR_ITERATIONS 4 | 25 #define TSS_DTOR_ITERATIONS 4 |
26 | 26 |
27 enum { | 27 enum { |
28 » thrd_success = 0, | 28 thrd_success = 0, |
29 » thrd_busy = 1, | 29 thrd_busy = 1, |
30 » thrd_error = 2, | 30 thrd_error = 2, |
31 » thrd_nomem = 3, | 31 thrd_nomem = 3, |
32 » thrd_timedout = 4, | 32 thrd_timedout = 4, |
33 }; | 33 }; |
34 | 34 |
35 enum { | 35 enum { |
36 » mtx_plain = 0, | 36 mtx_plain = 0, |
37 » mtx_recursive = 1, | 37 mtx_recursive = 1, |
38 » mtx_timed = 2, | 38 mtx_timed = 2, |
39 }; | 39 }; |
40 | 40 |
41 #define ONCE_FLAG_INIT 0 | 41 #define ONCE_FLAG_INIT 0 |
42 | 42 |
43 int thrd_create(thrd_t *, thrd_start_t, void *); | 43 int thrd_create(thrd_t*, thrd_start_t, void*); |
44 _Noreturn void thrd_exit(int); | 44 _Noreturn void thrd_exit(int); |
45 | 45 |
46 int thrd_detach(thrd_t); | 46 int thrd_detach(thrd_t); |
47 int thrd_join(thrd_t, int *); | 47 int thrd_join(thrd_t, int*); |
48 | 48 |
49 int thrd_sleep(const struct timespec *, struct timespec *); | 49 int thrd_sleep(const struct timespec*, struct timespec*); |
50 void thrd_yield(void); | 50 void thrd_yield(void); |
51 | 51 |
52 thrd_t thrd_current(void); | 52 thrd_t thrd_current(void); |
53 int thrd_equal(thrd_t, thrd_t); | 53 int thrd_equal(thrd_t, thrd_t); |
54 #ifndef __cplusplus | 54 #ifndef __cplusplus |
55 #define thrd_equal(A, B) ((A) == (B)) | 55 #define thrd_equal(A, B) ((A) == (B)) |
56 #endif | 56 #endif |
57 | 57 |
58 void call_once(once_flag *, void (*)(void)); | 58 void call_once(once_flag*, void (*)(void)); |
59 | 59 |
60 int mtx_init(mtx_t *, int); | 60 int mtx_init(mtx_t*, int); |
61 void mtx_destroy(mtx_t *); | 61 void mtx_destroy(mtx_t*); |
62 | 62 |
63 int mtx_lock(mtx_t *); | 63 int mtx_lock(mtx_t*); |
64 int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); | 64 int mtx_timedlock(mtx_t* __restrict, const struct timespec* __restrict); |
65 int mtx_trylock(mtx_t *); | 65 int mtx_trylock(mtx_t*); |
66 int mtx_unlock(mtx_t *); | 66 int mtx_unlock(mtx_t*); |
67 | 67 |
68 int cnd_init(cnd_t *); | 68 int cnd_init(cnd_t*); |
69 void cnd_destroy(cnd_t *); | 69 void cnd_destroy(cnd_t*); |
70 | 70 |
71 int cnd_broadcast(cnd_t *); | 71 int cnd_broadcast(cnd_t*); |
72 int cnd_signal(cnd_t *); | 72 int cnd_signal(cnd_t*); |
73 | 73 |
74 int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *_
_restrict); | 74 int cnd_timedwait(cnd_t* __restrict, |
75 int cnd_wait(cnd_t *, mtx_t *); | 75 mtx_t* __restrict, |
| 76 const struct timespec* __restrict); |
| 77 int cnd_wait(cnd_t*, mtx_t*); |
76 | 78 |
77 int tss_create(tss_t *, tss_dtor_t); | 79 int tss_create(tss_t*, tss_dtor_t); |
78 void tss_delete(tss_t key); | 80 void tss_delete(tss_t key); |
79 | 81 |
80 int tss_set(tss_t, void *); | 82 int tss_set(tss_t, void*); |
81 void *tss_get(tss_t); | 83 void* tss_get(tss_t); |
82 | 84 |
83 #ifdef __cplusplus | 85 #ifdef __cplusplus |
84 } | 86 } |
85 #endif | 87 #endif |
86 | 88 |
87 #endif | 89 #endif |
OLD | NEW |