BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmt::TimedSemaphore Class Reference

#include <bslmt_timedsemaphore.h>

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

Public Types

enum  { e_TIMED_OUT }
 

Public Member Functions

 TimedSemaphore (bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 
 TimedSemaphore (int count, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 
 ~TimedSemaphore ()
 
void post ()
 
void post (int value)
 
int timedWait (const bsls::TimeInterval &absTime)
 
int tryWait ()
 
void wait ()
 
bsls::SystemClockType::Enum clockType () const
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The value timedWait returns when a timeout occurs.

Enumerator
e_TIMED_OUT 

Constructor & Destructor Documentation

◆ TimedSemaphore() [1/2]

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/2]

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.

Precondition
The behavior is undefined unless 0 <= count.

◆ ~TimedSemaphore()

bslmt::TimedSemaphore::~TimedSemaphore ( )
inline

Destroy this timed semaphore.

Member Function Documentation

◆ clockType()

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

Return the clock type used for timeouts.

◆ post() [1/2]

void bslmt::TimedSemaphore::post ( )
inline

Atomically increment the count of this timed semaphore.

◆ post() [2/2]

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

Atomically increase the count of this timed semaphore by the specified value.

Precondition
The behavior is undefined unless value > 0.

◆ timedWait()

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: