1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#if THREADS == 1
#define WRAPTHREADS_NOTHREADS 1
#elif defined(__unix__)
#define WRAPTHREADS_PTHREADS 1
#elif !defined(__STDC_NO_THREADS__)
#define WRAPTHREADS_C11THREADS 1
#elif defined(__has_include)
#if __has_include(<pthreads.h>)
#define WRAPTHREADS_PTHREADS 1
#elif __has_include(<threads.h>)
#define WRAPTHREADS_C11THREADS 1
#endif
#endif
#if WRAPTHREADS_PTHREADS
#include <pthread.h>
#define wrapthread_atomic _Atomic
#define wrapthread_return_t void *
#define wrapthread_return_val NULL
#define wrapthread_define_var_thread_t(x) pthread_t x
#define wrapthread_define_var_mutex_t(x) pthread_mutex_t x
#define wrapthread_define_struct_thread_t(x) pthread_t x
#define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x
#define wrapthread_define_if_threads(T, x) T x
#define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg)
#define wrapthread_join(a) pthread_join(a, NULL)
#define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL)
#define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
#elif WRAPTHREADS_C11THREADS
#include <threads.h>
#define wrapthread_atomic _Atomic
#define wrapthread_return_t int
#define wrapthread_return_val 0
#define wrapthread_define_var_thread_t(x) thrd_t x
#define wrapthread_define_var_mutex_t(x) mtx_t x
#define wrapthread_define_struct_thread_t(x) thrd_t x
#define wrapthread_define_struct_mutex_t(x) mtx_t x
#define wrapthread_define_if_threads(T, x) T x
#define wrapthread_create(a, f, arg) thrd_create(a, f, arg)
#define wrapthread_join(a) thrd_join(a, NULL)
#define wrapthread_mutex_init(a) mtx_init(a, mtx_plain)
#define wrapthread_mutex_lock(a) mtx_lock(a)
#define wrapthread_mutex_unlock(a) mtx_unlock(a)
#else
#define wrapthread_atomic
#define wrapthread_return_t int
#define wrapthread_return_val 0
#define wrapthread_define_var_thread_t(x) unused char x
#define wrapthread_define_var_mutex_t(x) unused char x
#define wrapthread_define_struct_thread_t(x) char x
#define wrapthread_define_struct_mutex_t(x) char x
#define wrapthread_define_if_threads(T, x) T x; (void)(x)
#define wrapthread_create(t, f, arg) f(arg)
#define wrapthread_join(a)
#define wrapthread_mutex_init(a)
#define wrapthread_mutex_lock(a)
#define wrapthread_mutex_unlock(a)
#endif
|