LLDB  mainline
Public Member Functions | Protected Attributes | 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]
Collaboration diagram for lldb_private::Predicate< T >:
Collaboration graph
[legend]

Public Member Functions

 Predicate ()
 Default constructor. More...
 
 Predicate (T initial_value)
 Construct with initial T value initial_value. More...
 
 ~Predicate ()=default
 Destructor. More...
 
GetValue () const
 Value get accessor. More...
 
void SetValue (T value, PredicateBroadcastType broadcast_type)
 Value set accessor. More...
 
template<typename C >
llvm::Optional< T > WaitFor (C Cond, const Timeout< std::micro > &timeout)
 Wait for Cond(m_value) to be true. More...
 
bool WaitForValueEqualTo (T value, const Timeout< std::micro > &timeout=llvm::None)
 Wait for m_value to be equal to value. More...
 
llvm::Optional< T > WaitForValueNotEqualTo (T value, const Timeout< std::micro > &timeout=llvm::None)
 Wait for m_value to not be equal to value. More...
 

Protected Attributes

m_value
 The templatized value T that we are protecting access to. More...
 
std::mutex m_mutex
 The mutex to use when accessing the data. More...
 
std::condition_variable m_condition
 The pthread condition variable to use for signaling that data available or changed. More...
 

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 41 of file Predicate.h.

Constructor & Destructor Documentation

◆ Predicate() [1/2]

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

Default constructor.

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

Definition at line 47 of file Predicate.h.

◆ Predicate() [2/2]

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 56 of file Predicate.h.

◆ ~Predicate()

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

Destructor.

Destroy the condition, mutex, and T objects.

Referenced by lldb_private::Predicate< bool >::Predicate().

Member Function Documentation

◆ 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.

Referenced by lldb_private::DebuggerThread::ContinueAsyncException(), lldb_private::Process::HandlePrivateEvent(), and CommunicationKDP::IsRunning().

◆ 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.

Referenced by CommunicationKDP::CheckForPacket(), lldb_private::DebuggerThread::ContinueAsyncException(), lldb_private::Process::HandlePrivateEvent(), CommunicationKDP::SendRequestAndGetReply(), lldb_private::IOHandler::SetPopped(), lldb_private::ConnectionFileDescriptor::SocketListenAndAccept(), lldb_private::Socket::TcpListen(), and lldb_private::EventDataReceipt::WaitForEventReceived().

◆ WaitFor()

template<class T>
template<typename C >
llvm::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.
  • None otherwise (timeout occurred).

Definition at line 123 of file Predicate.h.

Referenced by lldb_private::Predicate< bool >::WaitForValueEqualTo(), and lldb_private::Predicate< bool >::WaitForValueNotEqualTo().

◆ WaitForValueEqualTo()

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

Referenced by CommunicationKDP::WaitForNotRunningPrivate(), and lldb_private::IOHandler::WaitForPop().

◆ WaitForValueNotEqualTo()

template<class T>
llvm::Optional<T> lldb_private::Predicate< T >::WaitForValueNotEqualTo ( value,
const Timeout< std::micro > &  timeout = llvm::None 
)
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
  • None otherwise (timeout occurred).

Definition at line 185 of file Predicate.h.

Referenced by lldb_private::DebuggerThread::ContinueAsyncException(), and lldb_private::ConnectionFileDescriptor::GetListeningPort().

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< bool >::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< bool >::GetValue(), lldb_private::Predicate< bool >::SetValue(), and lldb_private::Predicate< bool >::WaitFor().

◆ m_value

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

The templatized value T that we are protecting access to.

Definition at line 193 of file Predicate.h.

Referenced by lldb_private::Predicate< bool >::GetValue(), lldb_private::Predicate< bool >::SetValue(), and lldb_private::Predicate< bool >::WaitFor().


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