Contains state helper macros. More...
Macros | |
| #define | PICOTM_STATE(_name, _type) |
| #define | PICOTM_STATE_ACQUIRE(_name, _self, _initialize, _error) |
| #define | PICOTM_STATE_INITIALIZER |
| #define | PICOTM_STATE_RELEASE(_name, _self) |
| #define | PICOTM_STATE_STATIC_DECL(_name, _type) |
| #define | PICOTM_STATE_STATIC_IMPL(_name, _type, _init, _uninit) |
| #define | PICOTM_STATE_TYPE(_name) |
Picotm provides helpers for managing state. State can be acquired and released as needed. When acquiring state, an initializer function sets up the state fields; when releasing the state, a clean-up function release the state fields. The example below declares state of type struct state
The macro PICOTM_STATE() defines state. Callers pass the state's name and data structure. The macro PICOTM_STATE_STATIC_IMPL() defines the corresponding implementation with the initializer and clean-up functions supplied as arguments.
At this point, PICOTM_STATE_TYPE() declares a variable of the state's type. State variables must be initialized with PICOTM_STATE_INITIALIZER.
The macro PICOTM_STATE_ACQUIRE() returns the state of a state variable. On it's first invocation, it runs the provided initializer function. Later invocations return the already initialized state; until the state is released with PICOTM_STATE_RELEASE(). This macro runs the provided clean-up function and releases the state.
State handling is not thread safe. For a thread-safe implemenation, PICOTM_SHARED_STATE() and its helpers are available.