BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL > Class Template Reference

#include <bslmt_fastpostsemaphoreimpl.h>

Public Types

enum  ReturnValue {
  e_SUCCESS = 0 , e_DISABLED = -1 , e_TIMED_OUT = -2 , e_WOULD_BLOCK = -3 ,
  e_FAILED = -4
}
 

Public Member Functions

 FastPostSemaphoreImpl (bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 
 FastPostSemaphoreImpl (int count, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 
 ~FastPostSemaphoreImpl ()=default
 Destroy this object.
 
void disable ()
 
void enable ()
 
void post ()
 Atomically increment the count of this semaphore.
 
void post (int value)
 
void postWithRedundantSignal (int value, int available, int blocked)
 
int take (int maximumToTake)
 
int takeAll ()
 
int timedWait (const bsls::TimeInterval &absTime)
 
int tryWait ()
 
int wait ()
 
bsls::SystemClockType::Enum clockType () const
 Return the clock type used for timeouts.
 
int getDisabledState () const
 
int getValue () const
 
bool isDisabled () const
 

Static Public Attributes

static const Int64 k_BLOCKED_INC = 0x0000000000000001LL
 
static const Int64 k_BLOCKED_MASK = 0x0000000000ffffffLL
 
static const Int64 k_DISABLED_GEN_INC = 0x0000000001000000LL
 
static const Int64 k_DISABLED_GEN_MASK = 0x000000000f000000LL
 
static const int k_DISABLED_GEN_SHIFT = 24
 
static const Int64 k_AVAILABLE_INC = 0x0000000010000000LL
 
static const Int64 k_AVAILABLE_MASK = 0xfffffffff0000000LL
 
static const int k_AVAILABLE_SHIFT = 28
 

Detailed Description

template<class ATOMIC_OP, class MUTEX, class CONDITION, class THREADUTIL>
class bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >

This class implements a semaphore type, optimized for post, for thread synchronization.

See bslmt_fastpostsemaphoreimpl

Member Enumeration Documentation

◆ ReturnValue

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
enum bslmt::FastPostSemaphoreImpl::ReturnValue
Enumerator
e_SUCCESS 
e_DISABLED 
e_TIMED_OUT 
e_WOULD_BLOCK 
e_FAILED 

Constructor & Destructor Documentation

◆ FastPostSemaphoreImpl() [1/2]

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::FastPostSemaphoreImpl ( bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME)
inlineexplicit

Create a FastPostSemaphoreImpl object initially having a count of 0. 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 . If clockType is not specified then the realtime system clock is used.

◆ FastPostSemaphoreImpl() [2/2]

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::FastPostSemaphoreImpl ( int  count,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
)
inlineexplicit

Create a FastPostSemaphoreImpl object initially having the specified count. 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 . If clockType is not specified then the realtime system clock is used.

◆ ~FastPostSemaphoreImpl()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::~FastPostSemaphoreImpl ( )
default

Member Function Documentation

◆ clockType()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
bsls::SystemClockType::Enum bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::clockType ( ) const
inline

◆ disable()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
void bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::disable ( )

Disable waiting on this semaphore. All subsequent invocations of wait, tryWait, and timedWait will fail immediately. All blocked invocations of wait and timedWait will fail immediately. If the semaphore is initially disabled, this call has no effect.

◆ enable()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
void bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::enable ( )

Enable waiting on this semaphore. If the semaphore is initially enabled, this call has no effect.

◆ getDisabledState()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::getDisabledState ( ) const
inline

Return an odd value if this semaphore is wait disabled, and an even value otherwise. The returned value can be used to detect a rapid short sequence of disable and enable invocations by comparing the value returned by getDisabledState before and after the sequence. For example, for any initial state of a semphore instance obj:

int state = obj.getDisabledState();
obj.disable();
obj.enable();
ASSERT(state != obj.getDisabledState());

This functionality is useful in higher-level components to determine if this semaphore was disabled during an operation.

◆ getValue()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::getValue ( ) const
inline

Return the current value (count > 0 ? count : 0) of this semaphore.

◆ isDisabled()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
bool bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::isDisabled ( ) const
inline

Return true if this semaphore is wait disabled, and false otherwise. Note that the semaphore is created in the "wait enabled" state.

◆ post() [1/2]

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
void bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::post ( )
inline

◆ post() [2/2]

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
void bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::post ( int  value)
inline

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

◆ postWithRedundantSignal()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
void bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::postWithRedundantSignal ( int  value,
int  available,
int  blocked 
)
inline

Atomically increase the count of this semaphore by the specified value. If the resources available to this semaphore is greater than or equal to the specified available and the number of threads blocked in this semaphore is greater than or equal to the specified blocked, always send a signal to potentially wake a waiting thread (even if the signal should not be needed). The behavior is undefined unless value > 0. Note that this method is provided to help mitigate issues in the implementation of underlying synchronization primitives.

◆ take()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::take ( int  maximumToTake)
inline

If the count of this semaphore is positive, reduce the count by the lesser of the count and the specified maximumToTake and return the magnitude of the change to the count. Otherwise, do nothing and return 0.

◆ takeAll()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::takeAll ( )
inline

If the count of this semaphore is positive, reduce the count to 0 and return the original value of the count. Otherwise, do nothing and return 0.

◆ timedWait()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::timedWait ( const bsls::TimeInterval absTime)
inline

If this semaphore is initially disabled, or becomes disabled while blocking, return e_DISABLED with no effect on the count. Otherwise, block until the count of this semaphore is a positive value or the specified absTime timeout expires. If the count of this semaphore is a positive value, return 0 and atomically decrement the count. If the absTime timeout expires, return e_TIMED_OUT with no effect on the count. Return e_FAILED if an error occurs. 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 documentation).

◆ tryWait()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::tryWait ( )
inline

If this semaphore is initially disabled, return e_DISABLED with no effect on the count. Otherwise, if the count of this semaphore is a positive value, return 0 and atomically decrement the count. If this semaphore is not disabled and the count of this semaphore is not a positive value, return e_WOULD_BLOCK with no effect on the count.

◆ wait()

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::wait ( )
inline

If this semaphore is initially disabled, or becomes disabled while blocking, return e_DISABLED with no effect on the count. Otherwise, block until the count of this semaphore is a positive value, return 0 and atomically decrement the count. Return e_FAILED if an error occurs.

Member Data Documentation

◆ k_AVAILABLE_INC

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_AVAILABLE_INC = 0x0000000010000000LL
static

◆ k_AVAILABLE_MASK

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_AVAILABLE_MASK = 0xfffffffff0000000LL
static

◆ k_AVAILABLE_SHIFT

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_AVAILABLE_SHIFT = 28
static

◆ k_BLOCKED_INC

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_BLOCKED_INC = 0x0000000000000001LL
static

◆ k_BLOCKED_MASK

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_BLOCKED_MASK = 0x0000000000ffffffLL
static

◆ k_DISABLED_GEN_INC

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_DISABLED_GEN_INC = 0x0000000001000000LL
static

◆ k_DISABLED_GEN_MASK

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const Int64 bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_DISABLED_GEN_MASK = 0x000000000f000000LL
static

◆ k_DISABLED_GEN_SHIFT

template<class ATOMIC_OP , class MUTEX , class CONDITION , class THREADUTIL >
const int bslmt::FastPostSemaphoreImpl< ATOMIC_OP, MUTEX, CONDITION, THREADUTIL >::k_DISABLED_GEN_SHIFT = 24
static

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