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
|
#if THREADS == 1
#define wrapthread_atomic
#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)
#elif defined(_WIN32)
#include <threads.h>
#define wrapthread_atomic _Atomic
#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, (int(*)(void *))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)
#elif defined(__unix__)
#include <pthread.h>
#define wrapthread_atomic _Atomic
#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)
#endif
|