Zth (libzth)
config.cpp
Go to the documentation of this file.
1
/*
2
* Zth (libzth), a cooperative userspace multitasking library.
3
* Copyright (C) 2019-2022 Jochem Rutgers
4
*
5
* This Source Code Form is subject to the terms of the Mozilla Public
6
* License, v. 2.0. If a copy of the MPL was not distributed with this
7
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
*/
9
10
#include <
libzth/config.h
>
11
#include <
libzth/util.h
>
12
13
#include <cstdlib>
14
#include <cstring>
15
16
namespace
zth
{
17
21
static
bool
config
(
char
const
* name,
bool
whenUnset)
22
{
23
// NOLINTNEXTLINE(concurrency-mt-unsafe)
24
char
const
* e = getenv(name);
25
26
if
(!e || !*e)
27
return
whenUnset;
28
else
if
(strcmp(e,
"0"
) == 0)
29
// Explicitly set to disabled
30
return
false
;
31
else
32
// Any other value is true
33
return
true
;
34
}
35
41
bool
config
(
int
env,
bool
whenUnset)
42
{
43
switch
(env) {
44
case
Env::EnableDebugPrint
: {
45
static
bool
const
e =
Config::SupportDebugPrint
46
&&
config
(
"ZTH_CONFIG_ENABLE_DEBUG_PRINT"
, whenUnset);
47
return
e;
48
}
49
case
Env::DoPerfEvent
: {
50
static
bool
const
e =
config
(
"ZTH_CONFIG_DO_PERF_EVENT"
, whenUnset);
51
return
e;
52
}
53
case
Env::PerfSyscall
: {
54
static
bool
const
e =
config
(
"ZTH_CONFIG_PERF_SYSCALL"
, whenUnset);
55
return
e;
56
}
57
case
Env::CheckTimesliceOverrun
: {
58
static
bool
const
e =
config
(
"ZTH_CONFIG_CHECK_TIMESLICE_OVERRUN"
, whenUnset);
59
return
e;
60
}
61
default
:
62
return
whenUnset;
63
}
64
}
65
66
}
// namespace zth
config.h
zth
Definition:
allocator.h:23
zth::config
bool config(int env, bool whenUnset)
Checks if a given environment option is set.
Definition:
config.cpp:41
zth::DefaultConfig::SupportDebugPrint
static bool const SupportDebugPrint
Add support to enable debug output prints.
Definition:
config.h:103
zth::Env::DoPerfEvent
@ DoPerfEvent
Definition:
config.h:33
zth::Env::PerfSyscall
@ PerfSyscall
Definition:
config.h:33
zth::Env::CheckTimesliceOverrun
@ CheckTimesliceOverrun
Definition:
config.h:33
zth::Env::EnableDebugPrint
@ EnableDebugPrint
Definition:
config.h:33
util.h
src
config.cpp
Generated by
1.9.1