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