Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bslmt::Latch Class Reference

#include <bslmt_latch.h>

List of all members.

Public Types

enum  { e_TIMED_OUT = Condition::e_TIMED_OUT }

Public Member Functions

 Latch (int count, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 Latch (int count, const bsl::chrono::system_clock &)
 Latch (int count, const bsl::chrono::steady_clock &)
 ~Latch ()
void arrive ()
void arriveAndWait ()
void countDown (int numEvents)
int timedWait (const bsls::TimeInterval &absTime)
template<class CLOCK , class DURATION >
int timedWait (const bsl::chrono::time_point< CLOCK, DURATION > &absTime)
void wait ()
bsls::SystemClockType::Enum clockType () const
int currentCount () const
bool tryWait () const

Detailed Description

This class defines a thread synchronization mechanism that allows one or more threads to wait until a certain number of operations have been performed by other threads.

See Component bslmt_latch


Member Enumeration Documentation

anonymous enum
Enumerator:
e_TIMED_OUT 

Constructor & Destructor Documentation

bslmt::Latch::Latch ( int  count,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
) [explicit]

Create a latch that will synchronize on the specified count number of events, and when count events have been recorded will release any waiting threads. 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. If clockType is not specified then the realtime system clock is used. The behavior is undefined unless 0 <= count.

bslmt::Latch::Latch ( int  count,
const bsl::chrono::system_clock &   
)

Create a latch that will synchronize on the specified count number of events, and when count events have been recorded will release any waiting threads. 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). The behavior is undefined unless 0 <= count.

bslmt::Latch::Latch ( int  count,
const bsl::chrono::steady_clock &   
)

Create a latch that will synchronize on the specified count number of events, and when count events have been recorded will release any waiting threads. 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). The behavior is undefined unless 0 <= count.

bslmt::Latch::~Latch (  ) 

Destroy this latch. The behavior is undefined if any threads are waiting on this latch.


Member Function Documentation

void bslmt::Latch::arrive (  ) 

Decrement the number of events that this latch is waiting for by 1, and if the resulting number of events is 0 release any waiting threads. The behavior is undefined unless the sum of all events that have arrived at this latch does not exceed the count with which it was initialized. Note that the initial count of events is supplied at construction.

void bslmt::Latch::arriveAndWait (  ) 

Decrement the number of events that this latch is waiting for by 1, and if the resulting number of events is 0 release any waiting threads; otherwise, block until the required number of events has been reached. The behavior is undefined unless the sum of all events that have arrived at this latch does not exceed the count with which it was initialized. Note that the initial count of events is supplied at construction. Also note that this method is equivalent to the following sequence:

          arrive();
          wait();
void bslmt::Latch::countDown ( int  numEvents  ) 

Decrement the number of events that this latch is waiting for by the specified numEvents, and if the resulting number of events is 0 release any waiting threads. The behavior is undefined unless numEvents > 0 and the sum of all events that have arrived at this latch does not exceed the count with which it was initialized. Note that the initial count of events is supplied at construction.

int bslmt::Latch::timedWait ( const bsls::TimeInterval absTime  ) 

Block until the number of events that this latch is waiting for reaches 0, or until the specified absTime timeout expires. Return 0 on success, e_TIMED_OUT on timeout, and a non-zero value different from e_TIMED_OUT if an error occurs. Errors are unrecoverable. After an error, the latch may be destroyed, but any other use has undefined behavior. absTime is an absolute time represented as an interval from some epoch as determined by the clock specified at construction (see Supported Clock-Types in the component-level documentation).

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

Block until the number of events that this latch is waiting for reaches 0, or until the specified absTime timeout expires. Return 0 on success, e_TIMED_OUT on timeout, and a non-zero value different from e_TIMED_OUT if an error occurs. Errors are unrecoverable. After an error, the latch may be destroyed, but any other use has undefined behavior. absTime is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point.

void bslmt::Latch::wait (  ) 

Block until the number of events that this latch is waiting for reaches 0.

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

Return the clock type used for timeouts.

int bslmt::Latch::currentCount (  )  const

Return the current number of events for which this latch is waiting. Note that this method is provided primarily for debugging purposes (i.e., its intended use is not as a synchronization mechanism), and can be used only as an upper bound for the current count without other external state information.

bool bslmt::Latch::tryWait (  )  const

Return true if this latch has already been released (i.e., the number of events the latch is waiting on is 0), and false otherwise. This method does not block. Note that a return value of true indicates a permanent state change (the latch has released and will never be un-released), but a return value of false is ephemeral and cannot typically be acted upon without additional external state information.


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