Zth (libzth)
init.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/macros.h
>
11
#include <
libzth/init.h
>
12
#include <
libzth/util.h
>
13
14
struct
zth_init_entry
const*
zth_init_head
=
nullptr
;
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:14
init.h
macros.h
zth_init_entry
Definition:
init.h:16
zth_init_entry::f
void(* f)(void)
Definition:
init.h:23
zth_init_entry::next
struct zth_init_entry const * next
Definition:
init.h:24
util.h
likely
#define likely(expr)
Marks the given expression to likely be evaluated to true.
Definition:
util.h:42
src
init.cpp
Generated by
1.9.1