2007-05-22 01:24:56 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : module_init.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : helpers for module initialization/shutdown.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// license: GPL; see lib/license.txt
|
|
|
|
|
|
|
|
#ifndef INCLUDED_MODULE_INIT
|
|
|
|
#define INCLUDED_MODULE_INIT
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initialization state of a module: class, source file, or whatever.
|
|
|
|
*
|
|
|
|
* can be declared as a static variable => no initializer needed,
|
|
|
|
* since 0 is the correct initial value.
|
|
|
|
*
|
|
|
|
* DO NOT change the value directly! (that'd break the carefully thought-out
|
|
|
|
* lock-free implementation)
|
|
|
|
**/
|
|
|
|
typedef uintptr_t ModuleInitState; // uintptr_t required by cpu_CAS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether initialization should go forward, i.e. initState is
|
2007-05-24 04:32:53 +02:00
|
|
|
* currently MODULE_UNINITIALIZED. increments initState afterwards.
|
2007-05-22 01:24:56 +02:00
|
|
|
*
|
|
|
|
* (the reason for this function - and tricky part - is thread-safety)
|
|
|
|
**/
|
|
|
|
extern bool ModuleShouldInitialize(volatile ModuleInitState* initState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* if module reference count is valid, decrement it.
|
|
|
|
* @return whether shutdown should go forward, i.e. this is the last
|
2007-05-24 04:32:53 +02:00
|
|
|
* shutdown call.
|
2007-05-22 01:24:56 +02:00
|
|
|
**/
|
|
|
|
extern bool ModuleShouldShutdown(volatile ModuleInitState* initState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* indicate the module is unusable, e.g. due to failure during init.
|
|
|
|
* all subsequent ModuleShouldInitialize/ModuleShouldShutdown calls
|
|
|
|
* for this initState will return false.
|
|
|
|
**/
|
|
|
|
extern void ModuleSetError(volatile ModuleInitState* initState);
|
|
|
|
|
2007-09-07 22:17:57 +02:00
|
|
|
/**
|
|
|
|
* @return whether the module is in the failure state, i.e. ModuleSetError
|
|
|
|
* was previously called on the same initState.
|
|
|
|
*
|
|
|
|
* this function is provided so that modules can report init failure to
|
|
|
|
* the second or later caller.
|
|
|
|
**/
|
|
|
|
extern bool ModuleIsError(volatile ModuleInitState* initState);
|
|
|
|
|
2007-05-22 01:24:56 +02:00
|
|
|
#endif // #ifndef INCLUDED_MODULE_INIT
|