3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
7 #ifndef _PDCLIB_THREADS_H
8 #define _PDCLIB_THREADS_H _PDCLIB_THREADS_H
9 #include "_PDCLIB_int.h"
10 #include "_PDCLIB_threadconfig.h"
18 #define thread_local _Thread_local
20 typedef _PDCLIB_once_flag once_flag;
25 mtx_recursive = (1 << 0),
28 _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed
40 #define ONCE_FLAG_INIT _PDCLIB_ONCE_FLAG_INIT
41 #ifdef _PDCLIB_ONCE_FLAG_IS_DONE
42 static inline void call_once( once_flag * flag, void (*func)( void ) )
44 if ( ! _PDCLIB_ONCE_FLAG_IS_DONE( flag ) )
46 _PDCLIB_call_once( flag, func );
50 void call_once( once_flag * flag, void (*func)( void ) );
54 typedef _PDCLIB_MTX_T mtx_t;
55 void mtx_destroy( mtx_t * mtx ) _PDCLIB_nothrow;
56 int mtx_init( mtx_t * mtx, int type ) _PDCLIB_nothrow;
57 int mtx_lock( mtx_t * mtx ) _PDCLIB_nothrow;
58 int mtx_timedlock( mtx_t * _PDCLIB_restrict mtx, const struct timespec * _PDCLIB_restrict ts ) _PDCLIB_nothrow;
59 int mtx_trylock( mtx_t * mtx ) _PDCLIB_nothrow;
60 int mtx_unlock( mtx_t * mtx ) _PDCLIB_nothrow;
64 typedef _PDCLIB_CND_T cnd_t;
65 int cnd_broadcast( cnd_t * cond ) _PDCLIB_nothrow;
66 void cnd_destroy( cnd_t * cond ) _PDCLIB_nothrow;
67 int cnd_init( cnd_t * cond ) _PDCLIB_nothrow;
68 int cnd_signal( cnd_t * cond ) _PDCLIB_nothrow;
69 int cnd_timedwait( cnd_t *_PDCLIB_restrict cond, mtx_t * _PDCLIB_restrict mtx, const struct timespec * _PDCLIB_restrict ts ) _PDCLIB_nothrow;
70 int cnd_wait( cnd_t * cond, mtx_t * mtx ) _PDCLIB_nothrow;
74 #define _PDCLIB_THRD_HAVE_MISC
75 typedef _PDCLIB_THRD_T thrd_t;
76 typedef int (*thrd_start_t)( void * );
78 int thrd_create( thrd_t * thr, thrd_start_t func, void * arg ) _PDCLIB_nothrow;
79 thrd_t thrd_current( void ) _PDCLIB_nothrow;
80 int thrd_detach( thrd_t thr ) _PDCLIB_nothrow;
81 int thrd_equal( thrd_t thr0, thrd_t thr1 ) _PDCLIB_nothrow;
83 /* Not nothrow: systems may use exceptions at thread exit */
84 _PDCLIB_noreturn void thrd_exit( int res );
85 /* Not nothrow: systems may potentially propogate exceptions out of thrd_join? */
86 int thrd_join( thrd_t thr, int * res );
89 #ifdef _PDCLIB_THRD_HAVE_MISC
90 int thrd_sleep( const struct timespec * duration, struct timespec * remaining ) _PDCLIB_nothrow;
91 void thrd_yield( void ) _PDCLIB_nothrow;
94 /* The behaviour of tss_t is woefully underspecified in the C11 standard. In
95 particular, it never specifies where/when/<b>if</b> destructors are called.
97 In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t
101 #define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS
103 typedef _PDCLIB_TSS_T tss_t;
104 typedef void (*tss_dtor_t)( void * );
106 int tss_create( tss_t * key, tss_dtor_t dtor ) _PDCLIB_nothrow;
107 void tss_delete( tss_t key ) _PDCLIB_nothrow;
108 void * tss_get( tss_t key ) _PDCLIB_nothrow;
109 int tss_set( tss_t key, void * val ) _PDCLIB_nothrow;