Zth (libzth)
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
w
y
z
Functions
a
b
c
e
f
g
i
l
m
n
o
p
r
s
t
u
v
w
y
z
Variables
Typedefs
Enumerations
Enumerator
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
~
Variables
a
b
c
d
e
f
g
h
l
m
n
p
r
s
t
u
v
Typedefs
a
b
c
d
e
f
i
l
p
r
s
t
v
Enumerations
Enumerator
c
d
e
f
l
m
n
p
r
s
u
w
Related Functions
Files
File List
File Members
All
_
a
b
c
d
e
f
g
i
l
m
p
r
s
t
u
z
Functions
c
m
z
Variables
Typedefs
Macros
_
a
b
c
d
e
f
g
i
l
m
p
r
t
u
z
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
init.h
Go to the documentation of this file.
1
#ifndef ZTH_INIT_H
2
#define ZTH_INIT_H
3
/*
4
* Zth (libzth), a cooperative userspace multitasking library.
5
* Copyright (C) 2019-2022 Jochem Rutgers
6
*
7
* This Source Code Form is subject to the terms of the Mozilla Public
8
* License, v. 2.0. If a copy of the MPL was not distributed with this
9
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10
*/
11
12
#include <
libzth/macros.h
>
13
14
#include <stdlib.h>
15
16
struct
zth_init_entry
{
17
#ifdef __cplusplus
18
zth_init_entry
(
void
(*
f
)(
void
),
zth_init_entry
const
*
next
)
19
:
f
(
f
)
20
,
next
(
next
)
21
{}
22
#endif
23
void (*
f
)(void);
24
struct
zth_init_entry
const*
next
;
25
};
26
27
extern
struct
zth_init_entry
const*
zth_init_head
;
28
extern
struct
zth_init_entry
*
zth_init_tail
;
29
EXTERN_C ZTH_EXPORT
void
zth_init
();
30
EXTERN_C ZTH_EXPORT
void
zth_preinit
();
31
EXTERN_C ZTH_EXPORT
int
zth_postdeinit
();
32
33
#ifdef __cplusplus
34
# ifndef ZTH_INIT_CALL
38
# define ZTH_INIT_CALL_(f, ...) \
39
struct f##__init : public zth_init_entry { \
40
f##__init() \
41
: zth_init_entry(&exec, nullptr) \
42
{ \
43
if(zth_init_tail) \
44
zth_init_tail->next = this; \
45
zth_init_tail = this; \
46
if(!zth_init_head) \
47
zth_init_head = this; \
48
} \
49
static void exec(){__VA_ARGS__}; \
50
};
51
# define ZTH_INIT_CALL(f) \
52
ZTH_INIT_CALL_(f, f();) \
53
static f##__init const f##__init_;
54
# endif
55
56
# ifndef ZTH_DEINIT_CALL
57
# ifdef ZTH_OS_BAREMETAL
58
# define ZTH_DEINIT_CALL( \
59
...)
// Don't bother doing any cleanup during shutdown.
60
# else
64
# define ZTH_DEINIT_CALL(f) \
65
ZTH_INIT_CALL_(f, atexit(f);) \
66
static f##__init f##__deinit_;
67
# endif
68
# endif
69
70
#endif
// __cplusplus
71
#endif
// ZTH_INIT_H
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
zth_postdeinit
int zth_postdeinit()
Initialization function to be called by the default-supplied main(), just before shutting down.
Definition:
main.cpp:42
zth_preinit
void zth_preinit()
Initialization function to be called by the default-supplied main(), before doing anything else.
Definition:
main.cpp:30
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
zth_init_entry::zth_init_entry
zth_init_entry(void(*f)(void), zth_init_entry const *next)
Definition:
init.h:18
include
libzth
init.h
Generated by
1.9.1