LLDB mainline
|
A C++ wrapper class for providing threaded access to a value of type T. More...
#include "lldb/Utility/Predicate.h"
Public Member Functions | |
Predicate () | |
Default constructor. | |
Predicate (T initial_value) | |
Construct with initial T value initial_value. | |
~Predicate ()=default | |
Destructor. | |
T | GetValue () const |
Value get accessor. | |
void | SetValue (T value, PredicateBroadcastType broadcast_type) |
Value set accessor. | |
template<typename C > | |
std::optional< T > | WaitFor (C Cond, const Timeout< std::micro > &timeout) |
Wait for Cond(m_value) to be true. | |
bool | WaitForValueEqualTo (T value, const Timeout< std::micro > &timeout=std::nullopt) |
Wait for m_value to be equal to value. | |
std::optional< T > | WaitForValueNotEqualTo (T value, const Timeout< std::micro > &timeout=std::nullopt) |
Wait for m_value to not be equal to value. | |
Protected Attributes | |
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. | |
std::condition_variable | m_condition |
The pthread condition variable to use for signaling that data available or changed. | |
Private Member Functions | |
void | Broadcast (T old_value, PredicateBroadcastType broadcast_type) |
Broadcast if needed. | |
Predicate (const Predicate &)=delete | |
const Predicate & | operator= (const Predicate &)=delete |
A C++ wrapper class for providing threaded access to a value of type T.
A templatized class that provides multi-threaded access to a value of type T. Threads can efficiently wait for bits within T to be set or reset, or wait for T to be set to be equal/not equal to a specified values.
Definition at line 42 of file Predicate.h.
|
inline |
Default constructor.
Initializes the mutex, condition and value with their default constructors.
Definition at line 48 of file Predicate.h.
|
inline |
Construct with initial T value initial_value.
Initializes the mutex and condition with their default constructors, and initializes the value with initial_value.
[in] | initial_value | The initial value for our T object. |
Definition at line 57 of file Predicate.h.
|
default |
Destructor.
Destroy the condition, mutex, and T objects.
|
privatedelete |
|
inlineprivate |
Broadcast if needed.
Check to see if we need to broadcast to our condition variable depending on the old_value and on the broadcast_type.
If broadcast_type is eBroadcastNever, no broadcast will be sent.
If broadcast_type is eBroadcastAlways, the condition variable will always be broadcast.
If broadcast_type is eBroadcastOnChange, the condition variable be broadcast if the owned value changes.
Definition at line 213 of file Predicate.h.
References lldb_private::eBroadcastAlways, lldb_private::eBroadcastOnChange, lldb_private::Predicate< T >::m_condition, and lldb_private::Predicate< T >::m_value.
Referenced by lldb_private::Predicate< T >::SetValue().
|
inline |
Value get accessor.
Copies the current m_value in a thread safe manor and returns the copied value.
Definition at line 71 of file Predicate.h.
References lldb_private::Predicate< T >::m_mutex, and lldb_private::Predicate< T >::m_value.
Referenced by lldb_private::Process::GetIOHandlerID(), lldb_private::DebuggerThread::HandleExceptionEvent(), lldb_private::Process::HandlePrivateEvent(), and CommunicationKDP::IsRunning().
|
privatedelete |
|
inline |
Value set accessor.
Set the contained m_value to new_value in a thread safe way and broadcast if needed.
[in] | value | The new value to set. |
[in] | broadcast_type | A value indicating when and if to broadcast. See the PredicateBroadcastType enumeration for details. |
Definition at line 90 of file Predicate.h.
References lldb_private::Predicate< T >::Broadcast(), lldb_private::Predicate< T >::m_mutex, and lldb_private::Predicate< T >::m_value.
Referenced by CommunicationKDP::CheckForPacket(), lldb_private::DebuggerThread::ContinueAsyncException(), lldb_private::EventDataReceipt::DoOnRemoval(), lldb_private::DebuggerThread::HandleExceptionEvent(), lldb_private::Process::HandlePrivateEvent(), CommunicationKDP::SendRequestAndGetReply(), and lldb_private::IOHandler::SetPopped().
|
inline |
Wait for Cond(m_value) to be true.
Waits in a thread safe way for Cond(m_value) to be true. If Cond(m_value) is already true, this function will return without waiting.
It is possible for the value to be changed between the time the value is set and the time the waiting thread wakes up. If the value no longer satisfies the condition when the waiting thread wakes up, it will go back into a wait state. It may be necessary for the calling code to use additional thread synchronization methods to detect transitory states.
[in] | Cond | The condition we want m_value satisfy. |
[in] | timeout | How long to wait for the condition to hold. |
Definition at line 123 of file Predicate.h.
References lldb_private::Predicate< T >::m_condition, lldb_private::Predicate< T >::m_mutex, and lldb_private::Predicate< T >::m_value.
Referenced by lldb_private::Predicate< T >::WaitForValueEqualTo(), and lldb_private::Predicate< T >::WaitForValueNotEqualTo().
|
inline |
Wait for m_value to be equal to value.
Waits in a thread safe way for m_value to be equal to value. If m_value is already equal to value, this function will return without waiting.
It is possible for the value to be changed between the time the value is set and the time the waiting thread wakes up. If the value no longer matches the requested value when the waiting thread wakes up, it will go back into a wait state. It may be necessary for the calling code to use additional thread synchronization methods to detect transitory states.
[in] | value | The value we want m_value to be equal to. |
[in] | timeout | How long to wait for the condition to hold. |
Definition at line 156 of file Predicate.h.
References lldb_private::Predicate< T >::WaitFor().
Referenced by lldb_private::EventDataReceipt::WaitForEventReceived(), CommunicationKDP::WaitForNotRunningPrivate(), and lldb_private::IOHandler::WaitForPop().
|
inline |
Wait for m_value to not be equal to value.
Waits in a thread safe way for m_value to not be equal to value. If m_value is already not equal to value, this function will return without waiting.
It is possible for the value to be changed between the time the value is set and the time the waiting thread wakes up. If the value is equal to the test value when the waiting thread wakes up, it will go back into a wait state. It may be necessary for the calling code to use additional thread synchronization methods to detect transitory states.
[in] | value | The value we want m_value to not be equal to. |
[in] | timeout | How long to wait for the condition to hold. |
Definition at line 185 of file Predicate.h.
References lldb_private::Predicate< T >::WaitFor().
Referenced by lldb_private::DebuggerThread::HandleExceptionEvent(), and lldb_private::Process::SyncIOHandler().
|
protected |
The pthread condition variable to use for signaling that data available or changed.
Definition at line 195 of file Predicate.h.
Referenced by lldb_private::Predicate< T >::Broadcast(), and lldb_private::Predicate< T >::WaitFor().
|
mutableprotected |
The mutex to use when accessing the data.
Definition at line 194 of file Predicate.h.
Referenced by lldb_private::Predicate< T >::GetValue(), lldb_private::Predicate< T >::SetValue(), and lldb_private::Predicate< T >::WaitFor().
|
protected |
The templatized value T that we are protecting access to.
Definition at line 193 of file Predicate.h.
Referenced by lldb_private::Predicate< T >::Broadcast(), lldb_private::Predicate< T >::GetValue(), lldb_private::Predicate< T >::SetValue(), and lldb_private::Predicate< T >::WaitFor().