Pyrogenesis
13997
|
Go to the source code of this file.
Typedefs | |
typedef intptr_t | ModuleInitState |
initialization state of a module (class, source file, etc.) must be initialized to zero (e.g. More... | |
Functions | |
LIB_API Status | ModuleInit (volatile ModuleInitState *initState, Status(*init)()) |
calls a user-defined init function if initState is zero. More... | |
LIB_API Status | ModuleShutdown (volatile ModuleInitState *initState, void(*shutdown)()) |
calls a user-defined shutdown function if initState is "initialized". More... | |
typedef intptr_t ModuleInitState |
initialization state of a module (class, source file, etc.) must be initialized to zero (e.g.
by defining as a static variable). DO NOT change the value!
Definition at line 35 of file module_init.h.
LIB_API Status ModuleInit | ( | volatile ModuleInitState * | initState, |
Status(*)() | init | ||
) |
calls a user-defined init function if initState is zero.
postcondition: initState is "initialized" if the callback returned INFO::OK, otherwise its Status return value (which prevents shutdown from being called).
thread-safe: subsequent callers spin until the callback returns (this prevents using partially-initialized modules)
note that callbacks typically reference static data and thus do not require a function argument, but that can later be added if necessary.
Definition at line 40 of file module_init.cpp.
LIB_API Status ModuleShutdown | ( | volatile ModuleInitState * | initState, |
void(*)() | shutdown | ||
) |
calls a user-defined shutdown function if initState is "initialized".
postcondition: initState remains set to the Status, or has been reset to zero to allow multiple init/shutdown pairs, e.g. in self-tests.
note: there is no provision for reference-counting because that turns out to be problematic (a user might call shutdown immediately after init; if this is the first use of the module, it will be shutdown prematurely, which is at least inefficient and possibly dangerous). instead, shutdown should only be called when cleanup is necessary (e.g. at exit before leak reporting) and it is certain that the module is no longer in use.
Definition at line 65 of file module_init.cpp.