BeRTOS
|
Debug macros for inter-module dependency checking. More...
#include <cfg/debug.h>
Go to the source code of this file.
Defines | |
#define | MOD_DEFINE(module) DB(extern bool module ## _initialized; bool module ## _initialized;) |
Declare a global variable for module dependency check. | |
#define | MOD_CHECK(module) |
Check that module was already initialized. | |
#define | MOD_INIT(module) |
Mark module as initialized. | |
#define | MOD_CLEANUP(module) |
Mark module as being no longer initialized. |
Debug macros for inter-module dependency checking.
These macros expand to nothing in release builds. In debug builds, they perform run-time dependency checks for modules.
The usage pattern looks like this:
MOD_DEFINE(phaser) void phaser_init(void) { MOD_CHECK(computer); MOD_CHECK(warp_core); [...charge weapons...] MOD_INIT(phaser); } void phaser_cleanup(void) { MOD_CLEANUP(phaser); [...disarm phaser...] }
Definition in file module.h.
#define MOD_CHECK | ( | module | ) |
Check that module was already initialized.
Put this check just before accessing any facility provided by a module that requires prior initialization.
#define MOD_CLEANUP | ( | module | ) |
Mark module as being no longer initialized.
Marking initialization requires the global data previously defined by MOD_DEFINE().
#define MOD_DEFINE | ( | module | ) | DB(extern bool module ## _initialized; bool module ## _initialized;) |
Declare a global variable for module dependency check.
#define MOD_INIT | ( | module | ) |
Mark module as initialized.
Marking initialization requires the global data previously defined by MOD_DEFINE().
To prevent double initialization bugs, an initialized module must first be cleaned up with MOD_CLEANUP() before calling MOD_INIT() another time.