Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bslmt::TimedSemaphore Class Reference

#include <bslmt_timedsemaphore.h>

List of all members.

Public Types

enum  { e_TIMED_OUT }

Public Member Functions

 TimedSemaphore (bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 TimedSemaphore (const bsl::chrono::system_clock &)
 TimedSemaphore (const bsl::chrono::steady_clock &)
 TimedSemaphore (int count, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 TimedSemaphore (int count, const bsl::chrono::system_clock &)
 TimedSemaphore (int count, const bsl::chrono::steady_clock &)
 ~TimedSemaphore ()
void post ()
void post (int value)
int timedWait (const bsls::TimeInterval &absTime)
template<class CLOCK , class DURATION >
int timedWait (const bsl::chrono::time_point< CLOCK, DURATION > &absTime)
int tryWait ()
void wait ()
bsls::SystemClockType::Enum clockType () const

Detailed Description

This class implements a portable timed semaphore type for thread synchronization. It forwards all requests to an appropriate platform-specific implementation.

See Component bslmt_timedsemaphore


Member Enumeration Documentation

anonymous enum
Enumerator:
e_TIMED_OUT 

Constructor & Destructor Documentation

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

Create a timed semaphore initially having a count of 0. Optionally specify a clockType indicating the type of the system clock against which the absTime timeouts passed to the timedWait methods 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::TimedSemaphore::TimedSemaphore ( const bsl::chrono::system_clock &   )  [explicit]

Create a timed semaphore initially having a count of 0. 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::TimedSemaphore::TimedSemaphore ( const bsl::chrono::steady_clock &   )  [explicit]

Create a timed semaphore initially having a count of 0. 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::TimedSemaphore::TimedSemaphore ( int  count,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
) [explicit]

Create a timed semaphore initially having the specified count. Optionally specify a clockType indicating the type of the system clock against which the absTime timeouts passed to the timedWait methods 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. The behavior is undefined unless 0 <= count.

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

Create a timed semaphore initially having the specified count. 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::TimedSemaphore::TimedSemaphore ( int  count,
const bsl::chrono::steady_clock &   
)

Create a timed semaphore initially having the specified count. 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::TimedSemaphore::~TimedSemaphore (  ) 

Destroy this timed semaphore.


Member Function Documentation

void bslmt::TimedSemaphore::post (  ) 

Atomically increment the count of this timed semaphore.

void bslmt::TimedSemaphore::post ( int  value  ) 

Atomically increase the count of this timed semaphore by the specified value. The behavior is undefined unless value > 0.

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

Block until the count of this semaphore is a positive value, or until the specified absTime timeout expires. 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). If the absTime timeout did not expire before the count attained a positive value, atomically decrement the count and return 0. If the absTime timeout did expire, return e_TIMED_OUT with no effect on the count. Any other value indicates that an error has occurred. Errors are unrecoverable. After an error, the semaphore may be destroyed, but any other use has undefined behavior. On Windows platforms, this method may return e_TIMED_OUT slightly before absTime.

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

Block until the count of this semaphore is a positive value, or until the specified absTime timeout expires. absTime is an absolute time represented by a time point with respect to some epoch, which is determined by the clock associated with the time point. If the absTime timeout did not expire before the count attained a positive value, atomically decrement the count and return 0. If the absTime timeout did expire, return e_TIMED_OUT with no effect on the count. Any other value indicates that an error has occurred. Errors are unrecoverable. After an error, the semaphore may be destroyed, but any other use has undefined behavior. On Windows platforms, this method may return e_TIMED_OUT slightly before absTime.

int bslmt::TimedSemaphore::tryWait (  ) 

If the count of this timed semaphore is positive, atomically decrement the count and return 0; otherwise, return a non-zero value with no effect on the count.

void bslmt::TimedSemaphore::wait (  ) 

Block until the count of this timed semaphore is a positive value, then atomically decrement the count and return.

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

Return the clock type used for timeouts.


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