The Pedigree Project 0.1
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
ConditionVariable Class Reference

#include <ConditionVariable.h>

+ Collaboration diagram for ConditionVariable:

Public Types

enum  Error {
  NoError , TimedOut , Interrupted , TerminationDeferred ,
  MutexNotLocked
}
 

Public Member Functions

MUST_USE_RESULT bool wait (Mutex &mutex, Time::Timestamp &timeout, Error &error, WaitQueue::StackDiscardCleanup onStackDiscard=nullptr, void *stackDiscardContext=nullptr)
 
MUST_USE_RESULT bool wait (Mutex &mutex, Error &error, WaitQueue::StackDiscardCleanup onStackDiscard=nullptr, void *stackDiscardContext=nullptr)
 
void waitForCompletion (Mutex &mutex)
 
void signal ()
 
void broadcast ()
 

Static Public Member Functions

static bool mutexAcquired (Error error)
 

Private Attributes

WaitQueue m_Waiters
 
void * m_Private
 Private data.
 

Detailed Description

ConditionVariable provides an abstraction over condition variables.

Definition at line 35 of file ConditionVariable.h.

Member Enumeration Documentation

◆ Error

enum ConditionVariable::Error

Definition at line 37 of file ConditionVariable.h.

Constructor & Destructor Documentation

◆ ConditionVariable()

ConditionVariable::ConditionVariable ( )

Definition at line 58 of file ConditionVariable.cc.

◆ ~ConditionVariable()

ConditionVariable::~ConditionVariable ( )

Definition at line 60 of file ConditionVariable.cc.

Member Function Documentation

◆ broadcast()

void ConditionVariable::broadcast ( )

Wake up all threads currently waiting.

Definition at line 162 of file ConditionVariable.cc.

Referenced by MqueueNetlinkSocket::lastDescriptorClosed(), UnlikelyLock::leave(), EventFd::readValue(), UnlikelyLock::release(), and EventFd::writeValue().

+ Here is the caller graph for this function:

◆ mutexAcquired()

static bool ConditionVariable::mutexAcquired ( Error  error)
inlinestatic

Whether wait() returned with ownership of the supplied mutex.

Definition at line 40 of file ConditionVariable.h.

Referenced by MemoryPool::allocateDoer(), Buffer< T, allowShortOperation >::canRead(), Buffer< T, allowShortOperation >::canWrite(), Buffer< T, allowShortOperation >::read(), EventFd::readValue(), Pipe::waitForReader(), and EventFd::writeValue().

+ Here is the caller graph for this function:

◆ signal()

void ConditionVariable::signal ( )

Wake up at least one thread that is currently waiting.

Definition at line 158 of file ConditionVariable.cc.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), ProducerConsumer::destroy(), and MemoryPool::free().

+ Here is the caller graph for this function:

◆ wait() [1/2]

bool ConditionVariable::wait ( Mutex &  mutex,
Error &  error,
WaitQueue::StackDiscardCleanup  onStackDiscard = nullptr,
void *  stackDiscardContext = nullptr 
)

Wait for a signal on the condition variable with no timeout.

Definition at line 62 of file ConditionVariable.cc.

References wait().

◆ wait() [2/2]

bool ConditionVariable::wait ( Mutex &  mutex,
Time::Timestamp &  timeout,
Error &  error,
WaitQueue::StackDiscardCleanup  onStackDiscard = nullptr,
void *  stackDiscardContext = nullptr 
)

Wait for a signal on the condition variable with a specific timeout.

The timeout specifies a relative deadline in nanoseconds. Zero requests an immediate timeout; use Time::Infinity or the overload without a timeout parameter to wait indefinitely. If the operation times out, the value is set to zero. If it succeeds first, the value is the remaining timeout.

The mutex is reacquired for every returning outcome. Forced thread termination returns TerminationDeferred with the mutex held so the caller can retire stack-owned state while unwinding toward a thread boundary.

Parameters
[in]mutexan acquired mutex protecting the resource.
[in,out]timeouta relative timeout in nanoseconds, zero for an immediate deadline, or Time::Infinity for no deadline.

Definition at line 69 of file ConditionVariable.cc.

References ProcessorBase::information().

Referenced by MemoryPool::allocateDoer(), EventFd::readValue(), wait(), Pipe::waitForReader(), and EventFd::writeValue().

+ Here is the caller graph for this function:

◆ waitForCompletion()

void ConditionVariable::waitForCompletion ( Mutex &  mutex)

Wait for a lifetime predicate which must be rechecked with mutex held.

Signal and terminal events are delivered but cannot abandon the wait or mutex reacquisition. A delivered signal remains recorded on the current Thread so an outer syscall boundary can still report interruption after the protected lifetime state has drained.

Definition at line 144 of file ConditionVariable.cc.

References WaitQueue::Guard::waitAndUnlockForCompletion().

Referenced by UnlikelyLock::acquire(), and UnlikelyLock::enter().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_Private

void* ConditionVariable::m_Private
private

Private data.

Definition at line 94 of file ConditionVariable.h.

◆ m_Waiters

WaitQueue ConditionVariable::m_Waiters
private

Definition at line 90 of file ConditionVariable.h.


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