LLDB mainline
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
lldb_private::Predicate< T > Class Template Reference

A C++ wrapper class for providing threaded access to a value of type T. More...

#include "lldb/Utility/Predicate.h"

Inheritance diagram for lldb_private::Predicate< T >:
Inheritance graph
[legend]

Public Member Functions

 Predicate ()
 Default constructor.
 
 Predicate (T initial_value)
 Construct with initial T value initial_value.
 
 ~Predicate ()=default
 Destructor.
 
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

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 Predicateoperator= (const Predicate &)=delete
 

Detailed Description

template<class T>
class lldb_private::Predicate< T >

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.

Constructor & Destructor Documentation

◆ Predicate() [1/3]

template<class T >
lldb_private::Predicate< T >::Predicate ( )
inline

Default constructor.

Initializes the mutex, condition and value with their default constructors.

Definition at line 48 of file Predicate.h.

◆ Predicate() [2/3]

template<class T >
lldb_private::Predicate< T >::Predicate ( initial_value)
inline

Construct with initial T value initial_value.

Initializes the mutex and condition with their default constructors, and initializes the value with initial_value.

Parameters
[in]initial_valueThe initial value for our T object.

Definition at line 57 of file Predicate.h.

◆ ~Predicate()

template<class T >
lldb_private::Predicate< T >::~Predicate ( )
default

Destructor.

Destroy the condition, mutex, and T objects.

◆ Predicate() [3/3]

template<class T >
lldb_private::Predicate< T >::Predicate ( const Predicate< T > &  )
privatedelete

Member Function Documentation

◆ Broadcast()

template<class T >
void lldb_private::Predicate< T >::Broadcast ( old_value,
PredicateBroadcastType  broadcast_type 
)
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().

◆ GetValue()

template<class T >
T lldb_private::Predicate< T >::GetValue ( ) const
inline

Value get accessor.

Copies the current m_value in a thread safe manor and returns the copied value.

Returns
A copy of the current 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().

◆ operator=()

template<class T >
const Predicate & lldb_private::Predicate< T >::operator= ( const Predicate< T > &  )
privatedelete

◆ SetValue()

template<class T >
void lldb_private::Predicate< T >::SetValue ( value,
PredicateBroadcastType  broadcast_type 
)
inline

Value set accessor.

Set the contained m_value to new_value in a thread safe way and broadcast if needed.

Parameters
[in]valueThe new value to set.
[in]broadcast_typeA value indicating when and if to broadcast. See the PredicateBroadcastType enumeration for details.
See also
Predicate::Broadcast()

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().

◆ WaitFor()

template<class T >
template<typename C >
std::optional< T > lldb_private::Predicate< T >::WaitFor ( Cond,
const Timeout< std::micro > &  timeout 
)
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.

Parameters
[in]CondThe condition we want m_value satisfy.
[in]timeoutHow long to wait for the condition to hold.
Returns
m_value if Cond(m_value) is true, std::nullopt otherwise (timeout occurred).

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().

◆ WaitForValueEqualTo()

template<class T >
bool lldb_private::Predicate< T >::WaitForValueEqualTo ( value,
const Timeout< std::micro > &  timeout = std::nullopt 
)
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.

Parameters
[in]valueThe value we want m_value to be equal to.
[in]timeoutHow long to wait for the condition to hold.
Returns
true if the m_value is equal to value, false otherwise (timeout occurred).

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().

◆ WaitForValueNotEqualTo()

template<class T >
std::optional< T > lldb_private::Predicate< T >::WaitForValueNotEqualTo ( value,
const Timeout< std::micro > &  timeout = std::nullopt 
)
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.

Parameters
[in]valueThe value we want m_value to not be equal to.
[in]timeoutHow long to wait for the condition to hold.
Returns
m_value if m_value != value, std::nullopt otherwise (timeout occurred).

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().

Member Data Documentation

◆ m_condition

template<class T >
std::condition_variable lldb_private::Predicate< T >::m_condition
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().

◆ m_mutex

template<class T >
std::mutex lldb_private::Predicate< T >::m_mutex
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().

◆ m_value

template<class T >
T lldb_private::Predicate< T >::m_value
protected

The documentation for this class was generated from the following file: