Loading...
Searching...
No Matches
Go to the documentation of this file.
18#if !defined(_DEBUG) && !defined(NDEBUG)
26#if !ZTH_THREADS && defined(ZTH_HAVE_LIBZMQ)
37#ifdef __clang_analyzer__
42#if defined(__GNUC__) || defined(CLANG_TIDY)
45# if __cplusplus < 201103L && !defined(decltype)
52# define ZTH_TLS_DECLARE(type, var) extern __thread type var;
53# define ZTH_TLS_DEFINE(type, var, init) __thread type var = init;
54# define ZTH_TLS_STATIC(type, var, init) static __thread type var = init;
55# define ZTH_TLS_MEMBER(type, var) static __thread type var;
56# define ZTH_TLS_SET(var, value) var = value
57# define ZTH_TLS_GET(var) var
63# define ZTH_ATTR_PRINTF gnu_printf
66# define GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
68# if GCC_VERSION < 50000
69# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
71# if GCC_VERSION >= 70000 && defined(__cplusplus) && __cplusplus < 201703L
72# pragma GCC diagnostic ignored "-Wnoexcept-type"
74# if GCC_VERSION >= 130000 && GCC_VERSION < 140000 && defined(__cplusplus)
75# pragma GCC diagnostic ignored "-Wmismatched-new-delete"
78# define UNUSED_PAR(name) name __attribute__((unused))
81# error Unsupported compiler. Please use gcc.
85# define __attribute__(x)
88#if defined(__cplusplus) && __cplusplus >= 201703L
89# define ZTH_FALLTHROUGH [[fallthrough]];
90#elif GCC_VERSION >= 70000L
91# define ZTH_FALLTHROUGH __attribute__((fallthrough));
93# define ZTH_FALLTHROUGH
96#ifndef ZTH_TLS_DECLARE
99# define ZTH_TLS_DECLARE(type, var) extern type var;
100# define ZTH_TLS_DEFINE(type, var, init) type var = init;
101# define ZTH_TLS_STATIC(type, var, init) static type var = init;
102# define ZTH_TLS_MEMBER(type, var) static type var;
103# define ZTH_TLS_SET(var, value) var = value
104# define ZTH_TLS_GET(var) var
107#ifndef ZTH_ATTR_PRINTF
108# define ZTH_ATTR_PRINTF printf
111#define __STDC_FORMAT_MACROS
115# define EXTERN_C extern "C"
122# define ZTH_EXPORT __attribute__((visibility("default")))
126# ifdef ZTH_INLINE_EMIT
129# define ZTH_INLINE __attribute__((gnu_inline)) inline
132# define ZTH_INLINE __attribute__((gnu_inline)) extern inline
163#elif __cplusplus < 201103L
181# define noexcept throw()
187# define alignas(...) __attribute__((aligned(sizeof(void*))))
189# ifndef LREF_QUALIFIED
190# define LREF_QUALIFIED
193# define inline17 static
195# ifndef static_assert
196# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
197# define ZTH_STATIC_ASSERT_FAILED_(line) zth_static_assert_failed_##line
198# define ZTH_STATIC_ASSERT_FAILED(line) ZTH_STATIC_ASSERT_FAILED_(line)
199# define static_assert(x, ...) \
200 typedef char ZTH_STATIC_ASSERT_FAILED( \
201 __LINE__)[(x) ? 1 : -1]
205# if __cplusplus < 201402L
208# define constexpr14 constexpr
212# define is_default = default;
214# ifndef LREF_QUALIFIED
215# define LREF_QUALIFIED &
218# if __cplusplus < 201703L
219# define inline17 static
221# define inline17 inline
226#if defined(__cplusplus) && !defined(__cpp_exceptions)
228# define catch(...) if(false)
229# define zth_throw(...) std::terminate()
231# define zth_throw(...) throw __VA_ARGS__
234#if defined(__SANITIZE_ADDRESS__) && !defined(ZTH_ENABLE_ASAN)
235# define ZTH_ENABLE_ASAN
244#if defined(__x86_64__)
245# define ZTH_ARCH_X86_64 1
246#elif defined(__i386__)
247# define ZTH_ARCH_X86 1
248#elif defined(__aarch64__) && defined(__APPLE__)
249# define ZTH_ARCH_ARM64 1
250#elif defined(__arm__)
251# define ZTH_ARCH_ARM 1
252# if defined(__ARM_ARCH) && __ARM_ARCH >= 6 && defined(__ARM_ARCH_PROFILE) \
253 && __ARM_ARCH_PROFILE == 'M'
254# define ZTH_ARM_HAVE_MPU
256# define __isb() __asm__ volatile("isb" ::: "memory")
257# define __dsb() __asm__ volatile("dsb" ::: "memory")
258# define __dmb() __asm__ volatile("dmb" ::: "memory")
259# define barrier() __dsb()
261# error Unsupported hardware platform.
265# if GCC_VERSION < 40802L
266# define barrier() __sync_synchronize()
268# define barrier() __atomic_thread_fence()
278#if defined(_WIN32) || defined(__CYGWIN__)
279# define ZTH_OS_WINDOWS 1
280# define _WANT_IO_C99_FORMATS 1
281# define __USE_MINGW_ANSI_STDIO 1
282# define WIN32_LEAN_AND_MEAN
284# if defined(UNICODE) || defined(_UNICODE)
285# error Do not use UNICODE. Use ANSI with UTF-8 instead.
288# define ZTH_HAVE_PTHREAD
291# ifdef ZTH_CONFIG_WRAP_IO
292# error ZTH_CONFIG_WRAP_IO is not supported on Windows.
294#elif defined(__linux__) && !defined(ZTH_OS_BAREMETAL)
295# define ZTH_OS_LINUX 1
296# define ZTH_OS_POSIX 1
298# define ZTH_HAVE_PTHREAD
300# define ZTH_HAVE_POLL
301# define ZTH_HAVE_MMAN
302#elif defined(__APPLE__)
303# include <TargetConditionals.h>
306# define ZTH_OS_POSIX 1
308# error Unsupported Apple platform.
310# define ZTH_HAVE_PTHREAD
311# define ZTH_HAVE_POLL
312# define ZTH_HAVE_MMAN
313# include <Availability.h>
314# if __MAC_OS_X_VERSION_MAX_ALLOWED < 1012
316# define ZTH_CUSTOM_CLOCK_GETTIME
318#elif defined(ZTH_ARCH_ARM)
320# define ZTH_OS_BAREMETAL 1
321# define ZTH_CUSTOM_CLOCK_GETTIME
323# ifndef NEWLIB_VERSION
324# define NEWLIB_VERSION (__NEWLIB__ * 10000L + __NEWLIB_MINOR__ * 100L + __NEWLIB_PATCHLEVEL__)
326# ifndef ZTH_FORMAT_LIMITED
327# define ZTH_FORMAT_LIMITED 1
330# error Unsupported OS.
333#if defined(_DEBUG) && defined(ZTH_HAVE_VALGRIND)
334# define ZTH_USE_VALGRIND
338# undef ZTH_HAVE_PTHREAD
356# ifndef ZTH_CONTEXT_WINFIBER
357# define ZTH_CONTEXT_WINFIBER
359# undef ZTH_CONTEXT_SIGALTSTACK
360# undef ZTH_CONTEXT_SJLJ
361# undef ZTH_CONTEXT_UCONTEXT
362#elif defined(ZTH_OS_BAREMETAL)
364# ifndef ZTH_CONTEXT_SJLJ
365# define ZTH_CONTEXT_SJLJ
367# if defined(ZTH_ARCH_ARM) && defined(__ARM_ARCH) && __ARM_ARCH >= 6 \
368 && defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
369# define ZTH_ARM_USE_PSP
370# define ZTH_STACK_SWITCH
372# undef ZTH_CONTEXT_SIGALTSTACK
373# undef ZTH_CONTEXT_UCONTEXT
374# undef ZTH_CONTEXT_WINFIBER
375#elif defined(ZTH_HAVE_VALGRIND)
377# ifndef ZTH_CONTEXT_UCONTEXT
378# define ZTH_CONTEXT_UCONTEXT
380# undef ZTH_CONTEXT_SIGALTSTACK
381# undef ZTH_CONTEXT_SJLJ
382# undef ZTH_CONTEXT_WINFIBER
385# undef ZTH_CONTEXT_SJLJ
386# undef ZTH_CONTEXT_WINFIBER
387# if defined(ZTH_CONTEXT_UCONTEXT)
388# undef ZTH_CONTEXT_SIGALTSTACK
389# elif !defined(ZTH_CONTEXT_SIGALTSTACK) || defined(ZTH_ENABLE_ASAN)
390# undef ZTH_CONTEXT_SIGALTSTACK
391# define ZTH_CONTEXT_UCONTEXT
395#ifdef ZTH_CONTEXT_WINFIBER
397# define WINVER 0x0501
398# elif WINVER < 0x0400
399# error WINVER should be at least 0x0400
402# define _WIN32_WINNT WINVER
403# elif _WIN32_WINNT < 0x0400
404# error _WIN32_WINNT should be at least 0x0400