1 #ifndef _PDCLIB_THREADS_H
\r
2 #define _PDCLIB_THREADS_H
\r
3 #include <_PDCLIB_int.h>
\r
4 #include <_PDCLIB_threadconfig.h>
\r
6 _PDCLIB_BEGIN_EXTERN_C
\r
8 #define thread_local _Thread_local
\r
10 typedef _PDCLIB_once_flag once_flag;
\r
14 mtx_recursive = (1 << 0),
\r
15 mtx_timed = (1 << 1),
\r
17 _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed
\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
32 if(!_PDCLIB_ONCE_FLAG_IS_DONE(flag)) {
\r
33 _PDCLIB_call_once(flag, func);
\r
37 void call_once(once_flag *flag, void (*func)(void));
\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
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
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
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
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
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
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
86 * In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t
\r
89 #if defined(_PDCLIB_TSS_T)
\r
90 #define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS
\r
92 typedef _PDCLIB_TSS_T tss_t;
\r
93 typedef void (*tss_dtor_t)(void*);
\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
101 _PDCLIB_END_EXTERN_C
\r