BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmt::TimedSemaphore Class Reference

#include <bslmt_timedsemaphore.h>

Public Types

enum  { e_TIMED_OUT }
 The value timedWait returns when a timeout occurs. More...
 

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 ()
 Destroy this timed semaphore.
 
void post ()
 Atomically increment the count of this timed semaphore.
 
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
 Return the clock type used for timeouts.
 

Detailed Description

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

See bslmt_timedsemaphore

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
e_TIMED_OUT 

Constructor & Destructor Documentation

◆ TimedSemaphore() [1/6]

bslmt::TimedSemaphore::TimedSemaphore ( bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME)
inlineexplicit

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. This method does not return normally unless there are sufficient system resources to construct the object.

◆ TimedSemaphore() [2/6]

bslmt::TimedSemaphore::TimedSemaphore ( const bsl::chrono::system_clock &  )
inlineexplicit

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). This method does not return normally unless there are sufficient system resources to construct the object.

◆ TimedSemaphore() [3/6]

bslmt::TimedSemaphore::TimedSemaphore ( const bsl::chrono::steady_clock &  )
inlineexplicit

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). This method does not return normally unless there are sufficient system resources to construct the object.

◆ TimedSemaphore() [4/6]

bslmt::TimedSemaphore::TimedSemaphore ( int  count,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
)
inlineexplicit

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. This method does not return normally unless there are sufficient system resources to construct the object. The behavior is undefined unless 0 <= count.

◆ TimedSemaphore() [5/6]

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

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). This method does not return normally unless there are sufficient system resources to construct the object. The behavior is undefined unless 0 <= count.

◆ TimedSemaphore() [6/6]

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

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). This method does not return normally unless there are sufficient system resources to construct the object. The behavior is undefined unless 0 <= count.

◆ ~TimedSemaphore()

bslmt::TimedSemaphore::~TimedSemaphore ( )
inline

Member Function Documentation

◆ clockType()

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

◆ post() [1/2]

void bslmt::TimedSemaphore::post ( )
inline

◆ post() [2/2]

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

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

◆ timedWait() [1/2]

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

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.

◆ timedWait() [2/2]

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

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.

◆ tryWait()

int bslmt::TimedSemaphore::tryWait ( )
inline

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.

◆ wait()

void bslmt::TimedSemaphore::wait ( )
inline

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


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