File size: 2,135 Bytes
8b7c501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#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

#ifndef PTHREADPOOL_USE_GCD
	#if defined(__APPLE__)
		#define PTHREADPOOL_USE_GCD 1
	#else
		#define PTHREADPOOL_USE_GCD 0
	#endif
#endif

#ifndef PTHREADPOOL_USE_EVENT
	#if defined(_WIN32) || defined(__CYGWIN__)
		#define PTHREADPOOL_USE_EVENT 1
	#else
		#define PTHREADPOOL_USE_EVENT 0
	#endif
#endif

#ifndef PTHREADPOOL_USE_CONDVAR
	#if PTHREADPOOL_USE_GCD || PTHREADPOOL_USE_FUTEX || PTHREADPOOL_USE_EVENT
		#define PTHREADPOOL_USE_CONDVAR 0
	#else
		#define PTHREADPOOL_USE_CONDVAR 1
	#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
#if defined(__GNUC__)
	#define PTHREADPOOL_CACHELINE_ALIGNED __attribute__((__aligned__(PTHREADPOOL_CACHELINE_SIZE)))
#elif defined(_MSC_VER)
	#define PTHREADPOOL_CACHELINE_ALIGNED __declspec(align(PTHREADPOOL_CACHELINE_SIZE))
#else
	#error "Platform-specific implementation of PTHREADPOOL_CACHELINE_ALIGNED required"
#endif

#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