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)
13struct zth_init_entry const* zth_init_head = nullptr;
14// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
15struct zth_init_entry* zth_init_tail = nullptr;
16
26{
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}
struct zth_init_entry * zth_init_tail
Definition init.cpp:15
void zth_init()
Perform one-time global initialization of the Zth library.
Definition init.cpp:25
struct zth_init_entry const * zth_init_head
Definition init.cpp:13
Definition init.h:13
void(* f)(void)
Definition init.h:20
struct zth_init_entry const * next
Definition init.h:21
#define likely(expr)
Marks the given expression to likely be evaluated to true.
Definition util.h:40