9#ifndef LLDB_UTILITY_PREDICATE_H
10#define LLDB_UTILITY_PREDICATE_H
15#include <condition_variable>
72 std::lock_guard<std::mutex> guard(
m_mutex);
91 std::lock_guard<std::mutex> guard(
m_mutex);
92#ifdef DB_PTHREAD_LOG_EVENTS
93 printf(
"%s (value = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, value,
122 template <
typename C>
124 std::unique_lock<std::mutex> lock(
m_mutex);
125 auto RealCond = [&] {
return Cond(
m_value); };
130 if (
m_condition.wait_for(lock, *timeout, RealCond))
158 return WaitFor([&value](T current) {
return value == current; }, timeout) !=
187 return WaitFor([&value](T current) {
return value != current; }, timeout);
217#ifdef DB_PTHREAD_LOG_EVENTS
218 printf(
"%s (old_value = 0x%8.8x, broadcast_type = %i) m_value = 0x%8.8x, "
220 __FUNCTION__, old_value, broadcast_type,
m_value, broadcast);
A C++ wrapper class for providing threaded access to a value of type T.
void SetValue(T value, PredicateBroadcastType broadcast_type)
Value set accessor.
T GetValue() const
Value get accessor.
std::condition_variable m_condition
The pthread condition variable to use for signaling that data available or changed.
const Predicate & operator=(const Predicate &)=delete
void Broadcast(T old_value, PredicateBroadcastType broadcast_type)
Broadcast if needed.
std::optional< T > WaitForValueNotEqualTo(T value, const Timeout< std::micro > &timeout=std::nullopt)
Wait for m_value to not be equal to value.
Predicate()
Default constructor.
std::optional< T > WaitFor(C Cond, const Timeout< std::micro > &timeout)
Wait for Cond(m_value) to be true.
T m_value
The templatized value T that we are protecting access to.
std::mutex m_mutex
The mutex to use when accessing the data.
bool WaitForValueEqualTo(T value, const Timeout< std::micro > &timeout=std::nullopt)
Wait for m_value to be equal to value.
Predicate(T initial_value)
Construct with initial T value initial_value.
~Predicate()=default
Destructor.
Predicate(const Predicate &)=delete
A class that represents a running process on the host machine.
@ eBroadcastNever
No broadcast will be sent when the value is modified.
@ eBroadcastAlways
Always send a broadcast when the value is modified.
@ eBroadcastOnChange
Only broadcast if the value changes when the value is modified.