Zth (libzth)
init.h File Reference
#include <libzth/macros.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  zth_init_entry
 

Macros

#define ZTH_INIT_CALL_(f, ...)
 Mark the given function f to be invoked during static initialization. More...
 
#define ZTH_INIT_CALL(f)
 
#define ZTH_DEINIT_CALL(f)
 Mark the given function f to be invoked at exit. More...
 

Functions

void zth_init ()
 Perform one-time global initialization of the Zth library. More...
 
void zth_preinit ()
 Initialization function to be called by the default-supplied main(), before doing anything else. More...
 
int zth_postdeinit ()
 Initialization function to be called by the default-supplied main(), just before shutting down. More...
 

Variables

struct zth_init_entry const * zth_init_head
 
struct zth_init_entryzth_init_tail
 

Macro Definition Documentation

◆ ZTH_DEINIT_CALL

#define ZTH_DEINIT_CALL (   f)
Value:
ZTH_INIT_CALL_(f, atexit(f);) \
static f##__init f##__deinit_;
#define ZTH_INIT_CALL_(f,...)
Mark the given function f to be invoked during static initialization.
Definition: init.h:38

Mark the given function f to be invoked at exit.

Definition at line 64 of file init.h.

◆ ZTH_INIT_CALL

#define ZTH_INIT_CALL (   f)
Value:
ZTH_INIT_CALL_(f, f();) \
static f##__init const f##__init_;

Definition at line 51 of file init.h.

◆ ZTH_INIT_CALL_

#define ZTH_INIT_CALL_ (   f,
  ... 
)
Value:
struct f##__init : public zth_init_entry { \
f##__init() \
: zth_init_entry(&exec, nullptr) \
{ \
zth_init_tail->next = this; \
zth_init_tail = this; \
zth_init_head = this; \
} \
static void exec(){__VA_ARGS__}; \
};
struct zth_init_entry * zth_init_tail
Definition: init.cpp:15
struct zth_init_entry const * zth_init_head
Definition: init.cpp:14
Definition: init.h:16
zth_init_entry(void(*f)(void), zth_init_entry const *next)
Definition: init.h:18

Mark the given function f to be invoked during static initialization.

Definition at line 38 of file init.h.

Function Documentation

◆ zth_init()

void zth_init ( )

Perform one-time global initialization of the Zth library.

Initialization is only done once. It is safe to call it multiple times.

The initialization sequence is initialized by ZTH_INIT_CALL() and processed in the same order as normal static initializers are executed.

Definition at line 25 of file init.cpp.

◆ zth_postdeinit()

int zth_postdeinit ( )

Initialization function to be called by the default-supplied main(), just before shutting down.

This function can be used to run machine/board-specific cleanup in main() before returning. The default (weak) implementation does nothing.

Returns
the exit code of the application, which overrides the returned value from main_fiber() when non-zero

Definition at line 42 of file main.cpp.

◆ zth_preinit()

void zth_preinit ( )

Initialization function to be called by the default-supplied main(), before doing anything else.

This function can be used to run machine/board-specific initialization in main() even before zth_init() is invoked. The default (weak) implementation does nothing.

Definition at line 30 of file main.cpp.

Variable Documentation

◆ zth_init_head

struct zth_init_entry const* zth_init_head
extern

Definition at line 14 of file init.cpp.

◆ zth_init_tail

struct zth_init_entry* zth_init_tail
extern

Definition at line 15 of file init.cpp.