Zth (libzth)
Loading...
Searching...
No Matches
init.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
3
*
4
* SPDX-License-Identifier: MPL-2.0
5
*/
6
7
#include <
libzth/macros.h
>
8
9
#include <
libzth/init.h
>
10
#include <
libzth/util.h
>
11
12
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
13
struct
zth_init_entry
const*
zth_init_head
=
nullptr
;
14
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
15
struct
zth_init_entry
*
zth_init_tail
=
nullptr
;
16
25
void
zth_init
()
26
{
27
if
(
likely
(!
zth_init_head
))
28
// Already initialized.
29
return
;
30
31
struct
zth_init_entry
const* p =
zth_init_head
;
32
zth_init_head
=
nullptr
;
33
34
while
(p) {
35
// p might be overwritten during p->f(), copy next first.
36
struct
zth_init_entry
const* p_next = p->
next
;
37
if
(p->
f
)
38
p->
f
();
39
p = p_next;
40
}
41
}
zth_init_tail
struct zth_init_entry * zth_init_tail
Definition
init.cpp:15
zth_init
void zth_init()
Perform one-time global initialization of the Zth library.
Definition
init.cpp:25
zth_init_head
struct zth_init_entry const * zth_init_head
Definition
init.cpp:13
init.h
macros.h
zth_init_entry
Definition
init.h:13
zth_init_entry::f
void(* f)(void)
Definition
init.h:20
zth_init_entry::next
struct zth_init_entry const * next
Definition
init.h:21
util.h
likely
#define likely(expr)
Marks the given expression to likely be evaluated to true.
Definition
util.h:40
src
init.cpp
Generated by
1.9.8