aboutsummaryrefslogtreecommitdiff
path: root/src/utils/wrapthread.h
blob: fc3200df261d46c941ee0234bb8ce4ff2cd8d79f (plain)
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
#if THREADS == 1
#define WRAPTHREADS_NOTHREADS 1
#endif

#if !WRAPTHREADS_NOTHREADS

	#if defined(__unix__)

		#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)

	#elif !defined(__STDC_NO_THREADS__)

		#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)

	#else
		#define WRAPTHREADS_NOTHREADS 1
	#endif


#if WRAPTHREADS_NOTHREADS

	#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

Generated with cgit - Back to sebastiano.tronto.net