Zth (libzth)
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#ifndef ZTH_CONFIG_H
2#define ZTH_CONFIG_H
3/*
4 * SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 */
8
14#include <libzth/macros.h>
15
16#ifdef __cplusplus
17# include <cstddef>
18# include <sys/time.h>
19
20# if __cplusplus >= 201103L
21# include <cstdint>
22# else
23# include <stdint.h>
24# endif
25
26# include <memory>
27
28namespace zth {
29
33
34bool config(int env /* one of Env::* */, bool whenUnset);
35
44# define zth_config(name) (::zth::config(::zth::Env::name, ::zth::Config::name))
45
46# if __cplusplus < 201103L
47# define ZTH_CONSTEXPR_RETURN(type, ...) \
48 type x = {__VA_ARGS__}; \
49 return x;
50# else // C++11 and up
51# define ZTH_CONSTEXPR_RETURN(type, ...) return {__VA_ARGS__};
52# endif // C++11 and up
53
56 static bool const Debug =
57# ifndef NDEBUG
58 true;
59# else
60 false;
61# endif
62
64 static bool const EnableAssert =
65# ifndef NDEBUG
66 Debug;
67# else
68 false;
69# endif
70
75 static bool const EnableFullAssert =
76# ifdef ZTH_OS_BAREMETAL
77 // Assume we are a bit short on memory.
78 false;
79# else
81# endif
82
84 static bool const EnableThreads =
85# if ZTH_THREADS
86 true;
87# else
88 false;
89# endif
90
97 static bool const EnableDebugPrint =
98# ifdef ZTH_CONFIG_ENABLE_DEBUG_PRINT
99 ZTH_CONFIG_ENABLE_DEBUG_PRINT;
100# else
101 false;
102# endif
103
109 static bool const SupportDebugPrint =
110# ifdef ZTH_OS_BAREMETAL
111 // Without OS, there is no environment to enable debugging when
112 // it is not enabled right away.
114# else
115 Debug;
116# endif
117
119 static bool const EnableColorLog = true;
120
125 static int const Print_banner = 12; // bright blue
126 static int const Print_worker = 5; // magenta
127 static int const Print_waiter = 1; // red
128 static int const Print_io = 9; // bright red
129 static int const Print_perf = 6; // cyan
130 static int const Print_fiber = 10; // bright green
131 static int const Print_context = 2; // green
132 static int const Print_sync = 11; // bright yellow
133 static int const Print_list = 8; // bright black
134 static int const Print_zmq = 9; // bright red
135 static int const Print_fsm = 14; // bright cyan
136 static int const Print_thread = 3; // yellow
137 static int const Print_coro = 13; // bright magenta
138
140 static size_t const DefaultFiberStackSize = 0x20000;
142 static bool const EnableStackGuard = Debug;
144 static bool const EnableStackWaterMark = Debug;
146 static bool const ContextSignals = false;
147
149 constexpr static struct timespec MinTimeslice()
150 {
151 ZTH_CONSTEXPR_RETURN(struct timespec, 0, 100000)
152 }
154 constexpr static struct timespec TimesliceOverrunReportThreshold()
155 {
156 ZTH_CONSTEXPR_RETURN(struct timespec, 0, 10000000)
157 }
158
160 static bool const CheckTimesliceOverrun = Debug;
163
165 static size_t const PerfEventBufferSize = 128;
169 static size_t const PerfVCDFileBuffer = 0x1000;
170
172 static bool const DoPerfEvent = false;
174 static bool const EnablePerfEvent =
175# ifdef ZTH_OS_BAREMETAL
176 // No environment, so only enable when we are actually saving it.
178# else
179 true;
180# endif
182 static bool const PerfSyscall = true;
183
185 static bool const NamedFsm = Debug || (EnableDebugPrint && Print_fsm > 0);
186
188 static bool const NamedObjects =
190
192 static bool const UseZMQ =
193# ifdef ZTH_HAVE_LIBZMQ
194 true;
195# else
196 false;
197# endif
198
200 static bool const UseLimitedFormatSpecifiers =
201# if defined(ZTH_FORMAT_LIMITED) && ZTH_FORMAT_LIMITED
202 true;
203# else
204 false;
205# endif
206
214 template <typename T>
215 struct Allocator {
216 typedef std::allocator<T> type;
217 };
218};
219} // namespace zth
220#endif // __cplusplus
221
222#include "zth_config.h"
223
224#undef ZTH_CONSTEXPR_RETURN
225#endif // ZTH_CONFIG_H
#define ZTH_CONSTEXPR_RETURN(type,...)
Definition config.h:51
std::allocator< T > type
Definition config.h:216
static int const Print_zmq
Definition config.h:134
static int const Print_perf
Definition config.h:129
static int const Print_context
Definition config.h:131
static bool const EnablePerfEvent
Enable (but not necessarily record) perf.
Definition config.h:174
static bool const DoPerfEvent
Record and output perf events.
Definition config.h:172
static int const Print_coro
Definition config.h:137
static size_t const DefaultFiberStackSize
Default fiber stack size in bytes.
Definition config.h:140
static bool const EnableDebugPrint
Actually do print the debug output.
Definition config.h:97
static int const Print_waiter
Definition config.h:127
static bool const Debug
This is a debug build when set to true.
Definition config.h:56
static bool const EnableAssert
When true, enable zth_assert().
Definition config.h:64
static int const Print_fiber
Definition config.h:130
static int const Print_worker
Definition config.h:126
static int const Print_banner
ANSI color used by zth_dbg(). Printing this category is disabled when set to 0.
Definition config.h:125
static size_t const PerfEventBufferSize
Buffer size for perf events.
Definition config.h:165
static bool const ContextSignals
Take POSIX signal into account when doing a context switch.
Definition config.h:146
static bool const EnableStackWaterMark
When true, enable stack watermark to detect maximum stack usage.
Definition config.h:144
static bool const EnableThreads
Add (Worker) thread support when true.
Definition config.h:84
static int const Print_thread
Definition config.h:136
static bool const NamedFsm
Use named FSM guards/actions.
Definition config.h:185
static bool const EnableStackGuard
When true, enable stack guards.
Definition config.h:142
static bool const CheckTimesliceOverrun
Check time slice overrun at every context switch.
Definition config.h:160
static bool const UseZMQ
Enable ZeroMQ support.
Definition config.h:192
static int const Print_list
Definition config.h:133
static int const Print_io
Definition config.h:128
static bool const NamedObjects
Use named objects.
Definition config.h:188
static bool const EnableColorLog
Enable colored output.
Definition config.h:119
static int const Print_sync
Definition config.h:132
static size_t const PerfVCDFileBuffer
VCD file buffer in bytes.
Definition config.h:169
static bool const PerfSyscall
Also record syscalls by perf.
Definition config.h:182
static constexpr struct timespec TimesliceOverrunReportThreshold()
Print an overrun reported when this timeslice is exceeded.
Definition config.h:154
static int const Print_fsm
Definition config.h:135
static bool const SupportDebugPrint
Add support to enable debug output prints.
Definition config.h:109
static bool const EnableFullAssert
Show failing expression in case of a failed assert.
Definition config.h:75
static constexpr struct timespec MinTimeslice()
Minimum time slice before zth::yield() actually yields.
Definition config.h:149
static size_t const PerfEventBufferThresholdToTriggerVCDWrite
Threshold when to force writing out VCD buffer.
Definition config.h:167
static bool const NamedSynchronizer
Save names for all zth::Synchronizer instances.
Definition config.h:162
static bool const UseLimitedFormatSpecifiers
Use limited formatting specifiers.
Definition config.h:200
@ DoPerfEvent
Definition config.h:31
@ PerfSyscall
Definition config.h:31
@ CheckTimesliceOverrun
Definition config.h:31
@ EnableDebugPrint
Definition config.h:31