aboutsummaryrefslogtreecommitdiff
path: root/src/utils/wrapthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/wrapthread.h')
-rw-r--r--src/utils/wrapthread.h83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h
index 843a37d..e14a473 100644
--- a/src/utils/wrapthread.h
+++ b/src/utils/wrapthread.h
@@ -1,61 +1,62 @@
1#if THREADS == 1 1#if THREADS == 1
2#define WRAPTHREADS_NOTHREADS 1 2 #define WRAPTHREADS_NOTHREADS 1
3#elif defined(__unix__)
4 #define WRAPTHREADS_PTHREADS 1
5#elif !defined(__STDC_NO_THREADS__)
6 #define WRAPTHREADS_C11THREADS 1
7#elif defined(__has_include)
8 #if __has_include(<pthreads.h>)
9 #define WRAPTHREADS_PTHREADS 1
10 #elif __has_include(<threads.h>)
11 #define WRAPTHREADS_C11THREADS 1
12 #endif
3#endif 13#endif
4 14
5#if !WRAPTHREADS_NOTHREADS 15#if WRAPTHREADS_PTHREADS
6
7 #if defined(__unix__)
8
9 #include <threads.h>
10
11 #define wrapthread_atomic _Atomic
12 16
13 #define wrapthread_return_t int 17 #include <pthread.h>
14 #define wrapthread_return_val 0
15 18
16 #define wrapthread_define_var_thread_t(x) thrd_t x 19 #define wrapthread_atomic _Atomic
17 #define wrapthread_define_var_mutex_t(x) mtx_t x
18 #define wrapthread_define_struct_thread_t(x) thrd_t x
19 #define wrapthread_define_struct_mutex_t(x) mtx_t x
20 20
21 #define wrapthread_define_if_threads(T, x) T x 21 #define wrapthread_return_t void *
22 #define wrapthread_return_val NULL
22 23
23 #define wrapthread_create(a, f, arg) thrd_create(a, f, arg) 24 #define wrapthread_define_var_thread_t(x) pthread_t x
24 #define wrapthread_join(a) thrd_join(a, NULL) 25 #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x
25 #define wrapthread_mutex_init(a) mtx_init(a, mtx_plain) 26 #define wrapthread_define_struct_thread_t(x) pthread_t x
26 #define wrapthread_mutex_lock(a) mtx_lock(a) 27 #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x
27 #define wrapthread_mutex_unlock(a) mtx_unlock(a)
28 28
29 #elif !defined(__STDC_NO_THREADS__) 29 #define wrapthread_define_if_threads(T, x) T x
30 30
31 #include <pthread.h> 31 #define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg)
32 #define wrapthread_join(a) pthread_join(a, NULL)
33 #define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL)
34 #define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
35 #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
32 36
33 #define wrapthread_atomic _Atomic 37#elif WRAPTHREADS_C11THREADS
34 38
35 #define wrapthread_return_t void * 39 #include <threads.h>
36 #define wrapthread_return_val NULL
37 40
38 #define wrapthread_define_var_thread_t(x) pthread_t x 41 #define wrapthread_atomic _Atomic
39 #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x
40 #define wrapthread_define_struct_thread_t(x) pthread_t x
41 #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x
42 42
43 #define wrapthread_define_if_threads(T, x) T x 43 #define wrapthread_return_t int
44 #define wrapthread_return_val 0
44 45
45 #define wrapthread_create(a, f, arg) \ 46 #define wrapthread_define_var_thread_t(x) thrd_t x
46 pthread_create(a, NULL, f, arg) 47 #define wrapthread_define_var_mutex_t(x) mtx_t x
47 #define wrapthread_join(a) pthread_join(a, NULL) 48 #define wrapthread_define_struct_thread_t(x) thrd_t x
48 #define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL) 49 #define wrapthread_define_struct_mutex_t(x) mtx_t x
49 #define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
50 #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
51 50
52 #else 51 #define wrapthread_define_if_threads(T, x) T x
53 #define WRAPTHREADS_NOTHREADS 1
54 #endif
55 52
56#endif 53 #define wrapthread_create(a, f, arg) thrd_create(a, f, arg)
54 #define wrapthread_join(a) thrd_join(a, NULL)
55 #define wrapthread_mutex_init(a) mtx_init(a, mtx_plain)
56 #define wrapthread_mutex_lock(a) mtx_lock(a)
57 #define wrapthread_mutex_unlock(a) mtx_unlock(a)
57 58
58#if WRAPTHREADS_NOTHREADS 59#else
59 60
60 #define wrapthread_atomic 61 #define wrapthread_atomic
61 62

Generated with cgit - Back to sebastiano.tronto.net