Crashpad
|
Tracks whether data are initialized, triggering a DCHECK assertion on an invalid data access. More...
#include "util/misc/initialization_state_dcheck.h"
Public Member Functions | |
State | state () const |
Returns the object’s state. More... | |
State | SetInitializing () |
Marks an uninitialized object as initializing. More... | |
State | SetValid () |
Marks an initializing object as valid. More... | |
Public Member Functions inherited from crashpad::InitializationState | |
bool | is_uninitialized () const |
Returns true if the object’s state is kStateUninitialized and it is safe to begin initializing it. | |
void | set_invalid () |
Sets the object’s state to kStateInvalid, marking initialization as being in process. | |
void | set_valid () |
Sets the object’s state to kStateValid, marking it initialized. | |
bool | is_valid () const |
Returns true if the the object’s state is kStateValid and it has been fully initialized and may be used. | |
Additional Inherited Members | |
Public Types inherited from crashpad::InitializationState | |
enum | State : uint8_t |
The object’s state. More... | |
Protected Member Functions inherited from crashpad::InitializationState | |
State | state () const |
Returns the object’s state. More... | |
void | set_state (State state) |
Sets the object’s state. More... | |
Tracks whether data are initialized, triggering a DCHECK assertion on an invalid data access.
Put an InitializationStateDcheck member into a class to help DCHECK that it’s in the right states at the right times. This is useful for classes with Initialize() methods. The chief advantage of InitializationStateDcheck over having a member variable to track state is that when the only use of the variable is to DCHECK, it wastes space (in memory and executable code) in non-DCHECK builds unless the code is also peppered with ugly #ifdef
s.
This implementation concentrates the ugly #ifdef
s in one location.
Usage:
State crashpad::InitializationStateDcheck::SetInitializing | ( | ) |
Marks an uninitialized object as initializing.
If the object is in the kStateUninitialized state, changes its state to kStateInvalid (initializing) and returns the previous (kStateUninitialized) state. Otherwise, returns the object’s current state.
Consumers of this class should not call this method. Use the INITIALIZATION_STATE_SET_INITIALIZING() macro instead.
State crashpad::InitializationStateDcheck::SetValid | ( | ) |
Marks an initializing object as valid.
If the object is in the kStateInvalid (initializing) state, changes its state to kStateValid and returns the previous (kStateInvalid) state. Otherwise, returns the object’s current state.
Consumers of this class should not call this method. Use the INITIALIZATION_STATE_SET_VALID() macro instead.
|
inline |
Returns the object’s state.
Consumers of this class should not call this method. Use the INITIALIZATION_STATE_SET_INITIALIZING(), INITIALIZATION_STATE_SET_VALID(), and INITIALIZATION_STATE_DCHECK_VALID() macros instead.