]> pd.if.org Git - pdclib.old/blob - includes/threads.h
[gandr] s/__lp64__/__LP64__/ to match GCC define
[pdclib.old] / includes / threads.h
1 #ifndef _PDCLIB_THREADS_H\r
2 #define _PDCLIB_THREADS_H\r
3 #include <_PDCLIB_int.h>\r
4 #include <_PDCLIB_threadconfig.h>\r
5 #include <time.h>\r
6 _PDCLIB_BEGIN_EXTERN_C\r
7 \r
8 #define thread_local _Thread_local\r
9 \r
10 typedef _PDCLIB_once_flag once_flag;\r
11 \r
12 enum {\r
13         mtx_plain               = 0,\r
14         mtx_recursive   = (1 << 0),\r
15         mtx_timed               = (1 << 1),\r
16 \r
17         _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed\r
18 };\r
19 \r
20 enum {\r
21         thrd_success    = 0,\r
22         thrd_timeout    = 1,\r
23         thrd_busy               = 2,\r
24         thrd_error              = 3,\r
25         thrd_nomem              = 4,\r
26 };\r
27 \r
28 #define ONCE_FLAG_INIT _PDCLIB_ONCE_FLAG_INIT\r
29 #if defined(_PDCLIB_ONCE_FLAG_IS_DONE)\r
30 static inline void call_once(once_flag *flag, void (*func)(void))\r
31 {\r
32         if(!_PDCLIB_ONCE_FLAG_IS_DONE(flag)) {\r
33                 _PDCLIB_call_once(flag, func);\r
34         }\r
35 }\r
36 #else\r
37 void call_once(once_flag *flag, void (*func)(void));\r
38 #endif\r
39 \r
40 #if defined(_PDCLIB_MTX_T)\r
41 typedef _PDCLIB_MTX_T   mtx_t;\r
42 void mtx_destroy(mtx_t *mtx) _PDCLIB_nothrow;\r
43 int mtx_init(mtx_t *mtx, int type) _PDCLIB_nothrow;\r
44 int mtx_lock(mtx_t *mtx) _PDCLIB_nothrow;\r
45 int mtx_timedlock(mtx_t *_PDCLIB_restrict mtx, const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow;\r
46 int mtx_trylock(mtx_t *mtx) _PDCLIB_nothrow;\r
47 int mtx_unlock(mtx_t *mtx) _PDCLIB_nothrow;\r
48 #endif\r
49 \r
50 #if defined(_PDCLIB_CND_T)\r
51 typedef _PDCLIB_CND_T   cnd_t;\r
52 int cnd_broadcast(cnd_t *cond) _PDCLIB_nothrow;\r
53 void cnd_destroy(cnd_t *cond) _PDCLIB_nothrow;\r
54 int cnd_init(cnd_t *cond) _PDCLIB_nothrow;\r
55 int cnd_signal(cnd_t *cond) _PDCLIB_nothrow;\r
56 int cnd_timedwait(cnd_t *_PDCLIB_restrict cond,\r
57         mtx_t *_PDCLIB_restrict mtx,\r
58         const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow;\r
59 int cnd_wait(cnd_t *cond, mtx_t *mtx) _PDCLIB_nothrow;\r
60 #endif\r
61 \r
62 #if defined(_PDCLIB_THRD_T)\r
63 #define _PDCLIB_THRD_HAVE_MISC\r
64 typedef _PDCLIB_THRD_T  thrd_t;\r
65 typedef int (*thrd_start_t)(void*);\r
66 \r
67 int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) _PDCLIB_nothrow;\r
68 thrd_t thrd_current(void) _PDCLIB_nothrow;\r
69 int thrd_detach(thrd_t thr) _PDCLIB_nothrow;\r
70 int thrd_equal(thrd_t thr0, thrd_t thr1) _PDCLIB_nothrow;\r
71 \r
72 /* Not nothrow: systems may use exceptions at thread exit */\r
73 _PDCLIB_noreturn void thrd_exit(int res);\r
74 /* Not nothrow: systems may potentially propogate exceptions out of thrd_join?*/\r
75 int thrd_join(thrd_t thr, int *res);\r
76 #endif\r
77 \r
78 #if defined(_PDCLIB_THRD_HAVE_MISC)\r
79 int thrd_sleep(const struct timespec *duration, struct timespec *remaining) _PDCLIB_nothrow;\r
80 void thrd_yield(void) _PDCLIB_nothrow;\r
81 #endif\r
82 \r
83 /* The behaviour of tss_t is woefully underspecified in the C11 standard. In \r
84  * particular, it never specifies where/when/<b>if</b> destructors are called.\r
85  *\r
86  * In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t\r
87  */\r
88 \r
89 #if defined(_PDCLIB_TSS_T)\r
90 #define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS\r
91 \r
92 typedef _PDCLIB_TSS_T   tss_t;\r
93 typedef void (*tss_dtor_t)(void*);\r
94 \r
95 int tss_create(tss_t *key, tss_dtor_t dtor) _PDCLIB_nothrow;\r
96 void tss_delete(tss_t key) _PDCLIB_nothrow;\r
97 void *tss_get(tss_t key) _PDCLIB_nothrow;\r
98 int tss_set(tss_t key, void *val) _PDCLIB_nothrow;\r
99 #endif\r
100 \r
101 _PDCLIB_END_EXTERN_C\r
102 #endif\r