Quick Links:

bal | bbl | bdl | bsl

Classes | Public Types | Public Member Functions

bslmt::Sluice Class Reference

#include <bslmt_sluice.h>

List of all members.

Classes

struct  GenerationDescriptor

Public Types

enum  { e_TIMED_OUT = TimedSemaphore::e_TIMED_OUT }

Public Member Functions

 Sluice (bslma::Allocator *basicAllocator=0)
 Sluice (bsls::SystemClockType::Enum clockType, bslma::Allocator *basicAllocator=0)
 Sluice (const bsl::chrono::system_clock &, bslma::Allocator *basicAllocator=0)
 Sluice (const bsl::chrono::steady_clock &, bslma::Allocator *basicAllocator=0)
 ~Sluice ()
const void * enter ()
void signalAll ()
void signalOne ()
int timedWait (const void *token, const bsls::TimeInterval &absTime)
template<class CLOCK , class DURATION >
int timedWait (const void *token, const bsl::chrono::time_point< CLOCK, DURATION > &absTime)
void wait (const void *token)
bsls::SystemClockType::Enum clockType () const

Detailed Description

This class controls the release of threads from a common synchronization point. One or more threads may "enter" a Sluice object, and then wait to be released. Either one waiting thread (via the signalOne method), or all waiting threads (via the signalAll method), may be signaled for release. In any case, Sluice provides a guarantee against starvation.

See Component bslmt_sluice


Member Enumeration Documentation

anonymous enum
Enumerator:
e_TIMED_OUT 

Constructor & Destructor Documentation

bslmt::Sluice::Sluice ( bslma::Allocator basicAllocator = 0  )  [explicit]
bslmt::Sluice::Sluice ( bsls::SystemClockType::Enum  clockType,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a sluice. 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 in the component documentation). If clockType is not specified then the realtime system clock is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bslmt::Sluice::Sluice ( const bsl::chrono::system_clock &  ,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a sluice. 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). Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bslmt::Sluice::Sluice ( const bsl::chrono::steady_clock &  ,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a sluice. 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). Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bslmt::Sluice::~Sluice (  ) 

Destroy this sluice.


Member Function Documentation

const void* bslmt::Sluice::enter (  ) 

Enter this sluice, and return the token on which the calling thread must subsequently wait. The behavior is undefined unless wait or timedWait is invoked with the token before this sluice is destroyed.

void bslmt::Sluice::signalAll (  ) 

Signal all threads that have entered this sluice and have not yet been released.

void bslmt::Sluice::signalOne (  ) 

Signal one thread that has entered this sluice and has not yet been released.

int bslmt::Sluice::timedWait ( const void *  token,
const bsls::TimeInterval absTime 
)

Wait for the specified token to be signaled, 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). Return 0 on success, and e_TIMED_OUT on timeout. Any other value indicates that an error has occurred. Errors are unrecoverable. After an error, the sluice may be destroyed, but any other use has undefined behavior. The token is released whether or not a timeout occurred. The behavior is undefined unless token was obtained from a call to enter by this thread, and was not subsequently released (via a call to timedWait or wait).

template<class CLOCK , class DURATION >
int bslmt::Sluice::timedWait ( const void *  token,
const bsl::chrono::time_point< CLOCK, DURATION > &  absTime 
)

Wait for the specified token to be signaled, 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 associated with the time point. Return 0 on success, and e_TIMED_OUT on timeout. Any other value indicates that an error has occurred. Errors are unrecoverable. After an error, the sluice may be destroyed, but any other use has undefined behavior. The token is released whether or not a timeout occurred. The behavior is undefined unless token was obtained from a call to enter by this thread, and was not subsequently released (via a call to timedWait or wait).

void bslmt::Sluice::wait ( const void *  token  ) 

Wait for the specified token to be signaled, and release the token. The behavior is undefined unless token was obtained from a call to enter by this thread, and was not subsequently released (via a call to timedWait or wait).

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

Return the clock type used for timeouts.


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