Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Functions | |
Status | ModuleInit (volatile ModuleInitState *initState, Status(*init)()) |
calls a user-defined init function if initState is zero. More... | |
Status | ModuleShutdown (volatile ModuleInitState *initState, void(*shutdown)()) |
calls a user-defined shutdown function if initState is "initialized". More... | |
Variables | |
static const Status | UNINITIALIZED = 0 |
static const Status | BUSY = ERR::AGAIN |
static const Status | INITIALIZED = INFO::SKIPPED |
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.
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.
|
static |
|
static |
|
static |