Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bslmt::Condition Class Reference

#include <bslmt_condition.h>

List of all members.

Public Types

enum  { e_TIMED_OUT = ConditionImpl<Platform::ThreadPolicy>::e_TIMED_OUT }

Public Member Functions

 Condition (bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 Condition (const bsl::chrono::system_clock &)
 Condition (const bsl::chrono::steady_clock &)
 ~Condition ()
void broadcast ()
void signal ()
int timedWait (Mutex *mutex, const bsls::TimeInterval &absTime)
template<class CLOCK , class DURATION >
int timedWait (Mutex *mutex, const bsl::chrono::time_point< CLOCK, DURATION > &absTime)
int wait (Mutex *mutex)
bsls::SystemClockType::Enum clockType () const

Detailed Description

This class implements a portable inter-thread signaling primitive.

See Component bslmt_condition


Member Enumeration Documentation

anonymous enum
Enumerator:
e_TIMED_OUT 

Constructor & Destructor Documentation

bslmt::Condition::Condition ( bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME  )  [explicit]

Create a condition variable object. Optionally specify a clockType indicating the type of the system clock against which the bsls::TimeInterval absTime timeouts passed to the timedWait method are to be interpreted (see Supported Clock-Types in the component-level documentation). If clockType is not specified then the realtime system clock is used.

bslmt::Condition::Condition ( const bsl::chrono::system_clock &   )  [explicit]

Create a condition variable object. Use the realtime system clock as the clock against which the absTime timeouts passed to the timedWait methods are interpreted (see Supported Clock-Types in the component-level documentation).

bslmt::Condition::Condition ( const bsl::chrono::steady_clock &   )  [explicit]

Create a condition variable object. Use the monotonic system clock as the clock against which the absTime timeouts passed to the timedWait methods are interpreted (see Supported Clock-Types in the component-level documentation).

bslmt::Condition::~Condition (  ) 

Destroy this condition variable object.


Member Function Documentation

void bslmt::Condition::broadcast (  ) 

Signal this condition variable object by waking up all threads that are currently waiting on this condition. If there are no threads waiting on this condition, this method has no effect.

void bslmt::Condition::signal (  ) 

Signal this condition variable object by waking up a single thread that is currently waiting on this condition. If there are no threads waiting on this condition, this method has no effect.

int bslmt::Condition::timedWait ( Mutex mutex,
const bsls::TimeInterval absTime 
)

Atomically unlock the specified mutex and suspend execution of the current thread until this condition object is "signaled" (i.e., one of the signal or broadcast methods is invoked on this object) or until the specified absTime timeout expires, then re-acquire a lock on the mutex. absTime is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see Supported Clock-Types in the component-level documentation), and is the earliest time at which the timeout may occur. The mutex remains locked by the calling thread upon returning from this function. Return 0 on success, and e_TIMED_OUT on timeout. Any other value indicates that an error has occurred. After an error, the condition may be destroyed, but any other use has undefined behavior. The behavior is undefined unless mutex is locked by the calling thread prior to calling this method. Note that spurious wakeups are rare but possible, i.e., this method may succeed (return 0) and return control to the thread without the condition object being signaled. Also note that the actual time of the timeout depends on many factors including system scheduling and system timer resolution, and may be significantly later than the time requested.

template<class CLOCK , class DURATION >
int bslmt::Condition::timedWait ( Mutex mutex,
const bsl::chrono::time_point< CLOCK, DURATION > &  absTime 
)

Atomically unlock the specified mutex and suspend execution of the current thread until this condition object is "signaled" (i.e., one of the signal or broadcast methods is invoked on this object) or until the specified absTime timeout expires, then re-acquire a lock on the mutex. absTime is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point, and is the earliest time at which the timeout may occur. The mutex remains locked by the calling thread upon returning from this function. Return 0 on success, and e_TIMED_OUT on timeout. Any other value indicates that an error has occurred. After an error, the condition may be destroyed, but any other use has undefined behavior. The behavior is undefined unless mutex is locked by the calling thread prior to calling this method. Note that spurious wakeups are rare but possible, i.e., this method may succeed (return 0) and return control to the thread without the condition object being signaled. Also note that the actual time of the timeout depends on many factors including system scheduling and system timer resolution, and may be significantly later than the time requested. Also note that the lock on mutex may be released and reacquired more than once before this method returns.

int bslmt::Condition::wait ( Mutex mutex  ) 

Atomically unlock the specified mutex and suspend execution of the current thread until this condition object is "signaled" (i.e., either signal or broadcast is invoked on this object in another thread), then re-acquire a lock on the mutex. Return 0 on success, and a non-zero value otherwise. Spurious wakeups are rare but possible; i.e., this method may succeed (return 0), and return control to the thread without the condition object being signaled. The behavior is undefined unless mutex is locked by the calling thread prior to calling this method. Note that mutex remains locked by the calling thread upon return from this function.

bsls::SystemClockType::Enum bslmt::Condition::clockType (  )  const

Return the clock type used for timeouts.


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