4 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief Debug macros for inter-module dependency checking.
10 * These macros expand to nothing in release builds. In debug
11 * builds, they perform run-time dependency checks for modules.
13 * The usage pattern looks like this:
18 * void phaser_init(void)
20 * MOD_CHECK(computer);
21 * MOD_CHECK(warp_core);
23 * [...charge weapons...]
28 * void phaser_cleanup(void)
30 * MOD_CLEANUP(phaser);
32 * [...disarm phaser...]
37 * \author Bernardo Innocenti <bernie@develer.com>
42 #include <cfg/debug.h>
45 * Declare a global variable for module dependency check.
47 * \see MOD_INIT(), MOD_CHECK()
49 #define MOD_DEFINE(module) DB(bool module ## _initialized;)
52 * Check that \a module was already initialized.
54 * Put this check just before accessing any facility
55 * provided by a module that requires prior initialization.
60 #define MOD_CHECK(module) \
62 DB(extern bool module ## _initialized;) \
63 ASSERT(module ## _initialized); \
67 * Mark module as initialized.
69 * Marking initialization requires the global data
70 * previously defined by MOD_DEFINE().
72 * To prevent double initialization bugs, an initialized
73 * module must first be cleaned up with MOD_CLEANUP() before
74 * calling MOD_INIT() another time.
76 * \see MOD_CLEANUP(), MOD_CHECK(), MOD_DEFINE()
78 #define MOD_INIT(module) \
80 ASSERT(!module ## _initialized); \
81 DB(module ## _initialized = true;) \
85 * Mark module as being no longer initialized.
87 * Marking initialization requires the global data
88 * previously defined by MOD_DEFINE().
90 * \see MOD_INIT(), MOD_CHECK(), MOD_DEFINE()
92 #define MOD_CLEANUP(module) \
94 ASSERT(module ## _initialized); \
95 DB(module ## _initialized = false;) \
98 #endif /* CFG_MODULE_H */