Go to the documentation of this file.
21 #if !defined(_DEBUG) && !defined(NDEBUG)
26 # define ZTH_THREADS 1
29 #if !ZTH_THREADS && defined(ZTH_HAVE_LIBZMQ)
31 # define ZTH_THREADS 1
40 #ifdef __clang_analyzer__
45 #if defined(__GNUC__) || defined(CLANG_TIDY)
48 # if __cplusplus < 201103L && !defined(decltype)
49 # define decltype(x) \
55 # define ZTH_TLS_DECLARE(type, var) extern __thread type var;
56 # define ZTH_TLS_DEFINE(type, var, init) __thread type var = init;
57 # define ZTH_TLS_STATIC(type, var, init) static __thread type var = init;
58 # define ZTH_TLS_MEMBER(type, var) static __thread type var;
59 # define ZTH_TLS_SET(var, value) var = value
60 # define ZTH_TLS_GET(var) var
66 # define ZTH_ATTR_PRINTF gnu_printf
69 # define GCC_VERSION \
70 (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
72 # if GCC_VERSION < 50000
73 # pragma GCC diagnostic ignored "-Wmissing-field-initializers"
75 # if GCC_VERSION >= 70000 && defined(__cplusplus) && __cplusplus < 201703L
76 # pragma GCC diagnostic ignored "-Wnoexcept-type"
79 # define UNUSED_PAR(name) name __attribute__((unused))
82 # error Unsupported compiler. Please use gcc.
86 # define __attribute__(x)
89 #if defined(__cplusplus) && __cplusplus >= 201703L
90 # define ZTH_FALLTHROUGH [[fallthrough]];
91 #elif GCC_VERSION >= 70000L
92 # define ZTH_FALLTHROUGH __attribute__((fallthrough));
94 # define ZTH_FALLTHROUGH
97 #ifndef ZTH_TLS_DECLARE
99 # define ZTH_THREADS 0
100 # define ZTH_TLS_DECLARE(type, var) extern type var;
101 # define ZTH_TLS_DEFINE(type, var, init) type var = init;
102 # define ZTH_TLS_STATIC(type, var, init) static type var = init;
103 # define ZTH_TLS_MEMBER(type, var) static type var;
104 # define ZTH_TLS_SET(var, value) var = value
105 # define ZTH_TLS_GET(var) var
108 #ifndef ZTH_ATTR_PRINTF
109 # define ZTH_ATTR_PRINTF printf
112 #define __STDC_FORMAT_MACROS
116 # define EXTERN_C extern "C"
123 # define ZTH_EXPORT __attribute__((visibility("default")))
127 # ifdef ZTH_INLINE_EMIT
130 # define ZTH_INLINE __attribute__((gnu_inline)) inline
133 # define ZTH_INLINE __attribute__((gnu_inline)) extern inline
164 #elif __cplusplus < 201103L
178 # define is_default \
182 # define noexcept throw()
185 # define nullptr NULL
188 # define alignas(...) __attribute__((aligned(sizeof(void*))))
190 # ifndef LREF_QUALIFIED
191 # define LREF_QUALIFIED
194 # define inline17 static
198 # if __cplusplus < 201402L
201 # define constexpr14 constexpr
205 # define is_default = default;
207 # ifndef LREF_QUALIFIED
208 # define LREF_QUALIFIED &
211 # if __cplusplus < 201703L
212 # define inline17 static
214 # define inline17 inline
219 #if defined(__cplusplus) && !defined(__cpp_exceptions)
220 # define try if(true)
221 # define catch(...) if(false)
222 # define zth_throw(e) std::abort()
224 # define zth_throw(e) throw e
227 #if defined(__SANITIZE_ADDRESS__) && !defined(ZTH_ENABLE_ASAN)
228 # define ZTH_ENABLE_ASAN
237 #if defined(__x86_64__)
238 # define ZTH_ARCH_X86_64 1
239 #elif defined(__i386__)
240 # define ZTH_ARCH_X86 1
241 #elif defined(__arm__)
242 # define ZTH_ARCH_ARM 1
243 # if defined(__ARM_ARCH) && __ARM_ARCH >= 6 && defined(__ARM_ARCH_PROFILE) \
244 && __ARM_ARCH_PROFILE == 'M'
245 # define ZTH_ARM_HAVE_MPU
247 # define __isb() __asm__ volatile("isb" ::: "memory")
248 # define __dsb() __asm__ volatile("dsb" ::: "memory")
249 # define __dmb() __asm__ volatile("dmb" ::: "memory")
250 # define barrier() __dsb()
252 # error Unsupported hardware platform.
256 # if GCC_VERSION < 40802L
257 # define barrier() __sync_synchronize()
259 # define barrier() __atomic_thread_fence()
269 #if defined(_WIN32) || defined(__CYGWIN__)
270 # define ZTH_OS_WINDOWS 1
271 # define _WANT_IO_C99_FORMATS 1
272 # define __USE_MINGW_ANSI_STDIO 1
273 # define WIN32_LEAN_AND_MEAN
275 # if defined(UNICODE) || defined(_UNICODE)
276 # error Do not use UNICODE. Use ANSI with UTF-8 instead.
279 # define ZTH_HAVE_PTHREAD
282 # ifdef ZTH_CONFIG_WRAP_IO
283 # error ZTH_CONFIG_WRAP_IO is not supported on Windows.
285 #elif defined(__linux__)
286 # define ZTH_OS_LINUX 1
287 # define ZTH_OS_POSIX 1
289 # define ZTH_HAVE_PTHREAD
291 # define ZTH_HAVE_POLL
292 # define ZTH_HAVE_MMAN
293 #elif defined(__APPLE__)
294 # include <TargetConditionals.h>
295 # ifdef TARGET_OS_MAC
296 # define ZTH_OS_MAC 1
297 # define ZTH_OS_POSIX 1
299 # error Unsupported Apple platform.
301 # define ZTH_HAVE_PTHREAD
302 # define ZTH_HAVE_POLL
303 # define ZTH_HAVE_MMAN
304 # include <Availability.h>
305 # if __MAC_OS_X_VERSION_MAX_ALLOWED < 1012
307 # define ZTH_CUSTOM_CLOCK_GETTIME
309 #elif defined(ZTH_ARCH_ARM)
311 # define ZTH_OS_BAREMETAL 1
312 # define ZTH_CUSTOM_CLOCK_GETTIME
314 # ifndef NEWLIB_VERSION
315 # define NEWLIB_VERSION \
316 (__NEWLIB__ * 10000L + __NEWLIB_MINOR__ * 100L + __NEWLIB_PATCHLEVEL__)
319 # error Unsupported OS.
322 #if defined(_DEBUG) && defined(ZTH_HAVE_VALGRIND)
323 # define ZTH_USE_VALGRIND
327 # undef ZTH_HAVE_PTHREAD
344 #ifdef ZTH_OS_WINDOWS
345 # ifndef ZTH_CONTEXT_WINFIBER
346 # define ZTH_CONTEXT_WINFIBER
348 # undef ZTH_CONTEXT_SIGALTSTACK
349 # undef ZTH_CONTEXT_SJLJ
350 # undef ZTH_CONTEXT_UCONTEXT
351 #elif defined(ZTH_OS_BAREMETAL)
353 # ifndef ZTH_CONTEXT_SJLJ
354 # define ZTH_CONTEXT_SJLJ
356 # if defined(ZTH_ARCH_ARM) && defined(__ARM_ARCH) && __ARM_ARCH >= 6 \
357 && defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
358 # define ZTH_ARM_USE_PSP
359 # define ZTH_STACK_SWITCH
361 # undef ZTH_CONTEXT_SIGALTSTACK
362 # undef ZTH_CONTEXT_UCONTEXT
363 # undef ZTH_CONTEXT_WINFIBER
364 #elif defined(ZTH_HAVE_VALGRIND)
366 # ifndef ZTH_CONTEXT_UCONTEXT
367 # define ZTH_CONTEXT_UCONTEXT
369 # undef ZTH_CONTEXT_SIGALTSTACK
370 # undef ZTH_CONTEXT_SJLJ
371 # undef ZTH_CONTEXT_WINFIBER
374 # undef ZTH_CONTEXT_SJLJ
375 # undef ZTH_CONTEXT_WINFIBER
376 # if defined(ZTH_CONTEXT_UCONTEXT)
377 # undef ZTH_CONTEXT_SIGALTSTACK
378 # elif !defined(ZTH_CONTEXT_SIGALTSTACK) || defined(ZTH_ENABLE_ASAN)
379 # undef ZTH_CONTEXT_SIGALTSTACK
380 # define ZTH_CONTEXT_UCONTEXT
384 #ifdef ZTH_CONTEXT_WINFIBER
386 # define WINVER 0x0501
387 # elif WINVER < 0x0400
388 # error WINVER should be at least 0x0400
390 # ifndef _WIN32_WINNT
391 # define _WIN32_WINNT WINVER
392 # elif _WIN32_WINNT < 0x0400
393 # error _WIN32_WINNT should be at least 0x0400