Template Class StateManager¶
Defined in File utilities.h
Class Documentation¶
-
template<size_t N>
class StateManager¶ Creates a state manager using a thread safe bitset object.
std::bitset does not provide atomic operations. This class achieves atomicity by protecting a bitset object with a mutex. Set, clear, and is_set functions are also provided.
The size N of the bitset object should be known at compile time.
All get and set and clear operations are done in a thread-safe manner using a mutex to protect operations. All set and clear operations notify any waiting threads.
The wait functions set a bitset indicating which bits are being waited on, and can be cancelled. When cancelled an exception is thrown.
Public Functions
-
inline StateManager(const std::map<size_t, std::string> &names_in)¶
-
inline StateManager()¶
-
inline void initialize(bool set_all = false)¶
-
inline void cancel_wait()¶
cancels all waiting threads and resets all pending bits
-
template<typename ...StateBits>
inline void set(StateBits... states)¶ set multiple state bits in variadic list
- Parameters:
states – [in] variadic list of state bits to set
-
template<typename ...StateBits>
inline void clear(StateBits... states)¶ clear multiple state bits in variadic list
- Parameters:
states – [in] variadic list of state bits to clear
-
inline void set_and_clear(size_t setstate, size_t clrstate)¶
atomically set and clear the specified state bits
- Parameters:
setstate – [in] state bit to set
clrstate – [in] state bit to clear
-
inline void set_and_clear(std::initializer_list<size_t> setstates, std::initializer_list<size_t> clrstates)¶
atomically set and clear the specified state bits
- Parameters:
setstates – [in] list of state bits to set
clrstates – [in] list of state bits to clear
-
inline void clear_all()¶
clear all state bits
-
inline bool is_clear(size_t state) const¶
is the specified state bit clear?
- Parameters:
state – [in] state bit to check
- Returns:
true|false
-
template<typename ...StateBits>
inline bool are_all_clear(StateBits... states) const¶ are all of the specified state bits clear?
- Parameters:
states – [in] variadic list of state bits to check
- Returns:
true|false
-
inline bool is_set(size_t state) const¶
is the specified state bit set?
- Parameters:
state – [in] state bit to check
- Returns:
true|false
-
template<typename ...StateBits>
inline bool are_all_set(StateBits... states) const¶ are all of the specified state bits set?
- Parameters:
states – [in] variadic list of state bits to check
- Returns:
true|false
-
template<typename ...StateBits>
inline bool is_any_set(StateBits... states) const¶ is any one of the specified state bits set?
- Parameters:
states – [in] variadic list of state bits to check
- Returns:
true|false
-
inline bool is_any_set() const¶
is any state bit in the bitset set?
- Returns:
true|false
-
inline void wait_for_state_set(size_t state)¶
wait for specified state to be set
this can throw an exception
- Parameters:
state – [in] state bit to wait for
-
inline void wait_for_state_clear(size_t state)¶
wait for specified state to be clear
this can throw an exception
- Parameters:
state – [in] state bit to wait for
-
template<typename ...StateBits>
inline void wait_for_states_clear(StateBits... states)¶ wait for specified states to be clear
this can throw an exception
- Parameters:
states – [in] state bits to wait for
-
inline void wait_for_match(const StateManager &obj)¶
wait for all state bits to match those of another StateManager object
this can throw an exception
- Parameters:
obj – [in] reference to another StateManager object for comparison
-
inline std::string get_state_name(size_t state) const¶
returns the name of a single state bit
- Parameters:
state – [in] state bit enum in a std::bitset
- Returns:
string
-
inline std::string get_set_names()¶
returns a space-delimited string of names of all set states
- Returns:
space-delimited string
-
inline std::string get_clear_names()¶
returns a space-delimited string of names of all clear states
- Returns:
space-delimited string
-
inline std::string get_pending_names()¶
returns a space-delimited string of names of all pending states
- Returns:
space-delimited string
-
inline StateManager(const std::map<size_t, std::string> &names_in)¶