aboutsummaryrefslogtreecommitdiff
path: root/src/threadpool-common.h
blob: 1a18c60c552b8f448c697ff7ef06a951ca0b9ab7 (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
#pragma once

#ifndef PTHREADPOOL_USE_CPUINFO
	#define PTHREADPOOL_USE_CPUINFO 0
#endif

#ifndef PTHREADPOOL_USE_FUTEX
	#if defined(__linux__)
		#define PTHREADPOOL_USE_FUTEX 1
	#elif defined(__EMSCRIPTEN__)
		#define PTHREADPOOL_USE_FUTEX 1
	#else
		#define PTHREADPOOL_USE_FUTEX 0
	#endif
#endif

/* Number of iterations in spin-wait loop before going into futex/condvar wait */
#define PTHREADPOOL_SPIN_WAIT_ITERATIONS 1000000

#define PTHREADPOOL_CACHELINE_SIZE 64
#define PTHREADPOOL_CACHELINE_ALIGNED __attribute__((__aligned__(PTHREADPOOL_CACHELINE_SIZE)))

#if defined(__clang__)
	#if __has_extension(c_static_assert) || __has_feature(c_static_assert)
		#define PTHREADPOOL_STATIC_ASSERT(predicate, message) _Static_assert((predicate), message)
	#else
		#define PTHREADPOOL_STATIC_ASSERT(predicate, message)
	#endif
#elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
	/* Static assert is supported by gcc >= 4.6 */
	#define PTHREADPOOL_STATIC_ASSERT(predicate, message) _Static_assert((predicate), message)
#else
	#define PTHREADPOOL_STATIC_ASSERT(predicate, message)
#endif

#ifndef PTHREADPOOL_INTERNAL
	#if defined(__ELF__)
		#define PTHREADPOOL_INTERNAL __attribute__((__visibility__("internal")))
	#elif defined(__MACH__)
		#define PTHREADPOOL_INTERNAL __attribute__((__visibility__("hidden")))
	#else
		#define PTHREADPOOL_INTERNAL
	#endif
#endif