-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsettings.h
131 lines (116 loc) · 4.81 KB
/
settings.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#if defined(LIBCO_C)
/*[amd64, arm, ppc, x86]:
by default, co_swap_function is marked as a text (code) section
if not supported, uncomment the below line to use mprotect instead */
/* #define LIBCO_MPROTECT */
/*[amd64]:
Win64 only: provides a substantial speed-up, but will thrash XMM regs
do not use this unless you are certain your application won't use SSE */
/* #define LIBCO_NO_SSE */
#if !defined(thread_local) /* User can override thread_local for obscure compilers */
#if !defined(LIBCO_MP) /* Running in single-threaded environment */
#define thread_local
#else /* Running in multi-threaded environment */
#if defined(__STDC__) /* Compiling as C Language */
#if defined(_MSC_VER) /* Don't rely on MSVC's C11 support */
#define thread_local __declspec(thread)
#elif __STDC_VERSION__ < 201112L /* If we are on C90/99 */
#if defined(__clang__) || defined(__GNUC__) /* Clang and GCC */
#define thread_local __thread
#else /* Otherwise, we ignore the directive (unless user provides their own) */
#define thread_local
#endif
#else /* C11 and newer define thread_local in threads.h */
#include <threads.h>
#endif
#elif defined(__cplusplus) /* Compiling as C++ Language */
#if __cplusplus < 201103L /* thread_local is a C++11 feature */
#if defined(_MSC_VER)
#define thread_local __declspec(thread)
#elif defined(__clang__) || defined(__GNUC__)
#define thread_local __thread
#else /* Otherwise, we ignore the directive (unless user provides their own) */
#define thread_local
#endif
#else /* In C++ >= 11, thread_local in a builtin keyword */
/* Don't do anything */
#endif
#endif
#endif
#endif
/* In alignas(a), 'a' should be a power of two that is at least the type's
alignment and at most the implementation's alignment limit. This limit is
2**13 on MSVC. To be portable to MSVC through at least version 10.0,
'a' should be an integer constant, as MSVC does not support expressions
such as 1 << 3.
The following C11 requirements are NOT supported on MSVC:
- If 'a' is zero, alignas has no effect.
- alignas can be used multiple times; the strictest one wins.
- alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
*/
#if !defined(alignas)
#if defined(__STDC__) /* C Language */
#if defined(_MSC_VER) /* Don't rely on MSVC's C11 support */
#define alignas(bytes) __declspec(align(bytes))
#elif __STDC_VERSION__ >= 201112L /* C11 and above */
#include <stdalign.h>
#elif defined(__clang__) || defined(__GNUC__) /* C90/99 on Clang/GCC */
#define alignas(bytes) __attribute__ ((aligned (bytes)))
#else /* Otherwise, we ignore the directive (user should provide their own) */
#define alignas(bytes)
#endif
#elif defined(__cplusplus) /* C++ Language */
#if __cplusplus < 201103L
#if defined(_MSC_VER)
#define alignas(bytes) __declspec(align(bytes))
#elif defined(__clang__) || defined(__GNUC__) /* C++98/03 on Clang/GCC */
#define alignas(bytes) __attribute__ ((aligned (bytes)))
#else /* Otherwise, we ignore the directive (unless user provides their own) */
#define alignas(bytes)
#endif
#else /* C++ >= 11 has alignas keyword */
/* Do nothing */
#endif
#endif /* = !defined(__STDC_VERSION__) && !defined(__cplusplus) */
#endif
#if !defined(LIBCO_ASSERT)
#include <assert.h>
#define LIBCO_ASSERT assert
#endif
#if defined (__OpenBSD__)
#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
#include <unistd.h>
#include <sys/mman.h>
static void* malloc_obsd(size_t size) {
long pagesize = sysconf(_SC_PAGESIZE);
char* memory = (char*)mmap(NULL, size + pagesize, PROT_READ|PROT_WRITE, MAP_STACK|MAP_PRIVATE|MAP_ANON, -1, 0);
if (memory == MAP_FAILED) return NULL;
*(size_t*)memory = size + pagesize;
memory += pagesize;
return (void*)memory;
}
static void free_obsd(void *ptr) {
char* memory = (char*)ptr - sysconf(_SC_PAGESIZE);
munmap(memory, *(size_t*)memory);
}
#define LIBCO_MALLOC malloc_obsd
#define LIBCO_FREE free_obsd
#endif
#endif
#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
#include <stdlib.h>
#define LIBCO_MALLOC malloc
#define LIBCO_FREE free
#endif
#if defined(_MSC_VER)
/* workaround for msvc preprocessor stringification behavior */
#define LIBCO_STRINGIFY(x) #x
#define LIBCO_TOSTRING(x) LIBCO_STRINGIFY(x)
#define section(name) __pragma(code_seg(LIBCO_TOSTRING("." #name))) __declspec(allocate(LIBCO_TOSTRING("." #name)))
#elif defined(__APPLE__)
#define section(name) __attribute__((section("__TEXT,__" #name)))
#else
#define section(name) __attribute__((section("." #name "#")))
#endif
/* if defined(LIBCO_C) */
#endif