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

#include <bslmt_turnstile.h>

Public Member Functions

 Turnstile (double rate, const bsls::TimeInterval &startTime=bsls::TimeInterval(0), const bsls::TimeInterval &minTimeToCallSleep=bsls::TimeInterval(1e-4))
 
 ~Turnstile ()=default
 Destroy this object.
 
void reset (double rate, const bsls::TimeInterval &startTime=bsls::TimeInterval(0), const bsls::TimeInterval &minTimeToCallSleep=bsls::TimeInterval(1e-4))
 
bsls::Types::Int64 waitTurn (bool sleep=true)
 
bsls::Types::Int64 lagTime () const
 

Detailed Description

This class provides a mechanism to meter time. Using either the constructor or the reset method, the client specifies rate, indicating the number of events per second that the turnstile will allow. The client then calls waitTurn, which will either sleep until the next event is to occur, or return immediately if waitTurn was called after the next event is due. If waitTurn is not called until after the next event is due, the turnstile is said to be lagging behind, and calls to waitTurn will not sleep until the events have caught up with the schedule. Note that calling waitTurn a single time does not bring a turnstile back on schedule. For example, if a turnstile's configured frequency is one event per second, and the client is 10 seconds behind schedule, if waitTurn were subsequently called once per second, the turnstile will remain at 10 seconds behind schedule. The amount by which events are lagging behind the schedule can be determined via the lagTime method, which returns the positive number of microseconds by which the turnstile is lagging, or 0 if the turnstile is not behind schedule.

See bslmt_turnstile

Constructor & Destructor Documentation

◆ Turnstile()

bslmt::Turnstile::Turnstile ( double  rate,
const bsls::TimeInterval startTime = bsls::TimeInterval(0),
const bsls::TimeInterval minTimeToCallSleep = bsls::TimeInterval(1e-4) 
)
explicit

Create a turnstile object that admits clients at the specified rate, expressed as the number of turns per second. Optionally specify the (relative) startTime of the first turn. If startTime is not specified, the first turn may be taken immediately. Optionally specify minTimeToCallSleep, the shortest period of time in seconds that the waitTurn function will go to sleep. The behavior is undefined unless 0 < rate.

◆ ~Turnstile()

bslmt::Turnstile::~Turnstile ( )
default

Member Function Documentation

◆ lagTime()

bsls::Types::Int64 bslmt::Turnstile::lagTime ( ) const

Return the positive number of microseconds difference between the the current time and the next turn, indicating that the turnstile is lagging behind the configured rate. Otherwise, return 0.

◆ reset()

void bslmt::Turnstile::reset ( double  rate,
const bsls::TimeInterval startTime = bsls::TimeInterval(0),
const bsls::TimeInterval minTimeToCallSleep = bsls::TimeInterval(1e-4) 
)

Reset the rate of this turnstile to the specified rate, expressed as the number of turns per second. Optionally specify the (relative) startTime of the first turn. If startTime is not specified, the first turn may be taken immediately. Optionally specify minTimeToCallSleep, the shortest period of time in seconds that the waitTurn function will go to sleep. The behavior is undefined unless 0 < rate. Note that threads blocked on waitTurn are not interrupted.

◆ waitTurn()

bsls::Types::Int64 bslmt::Turnstile::waitTurn ( bool  sleep = true)

Sleep until the next turn may be taken or return immediately if the optionally specified sleep is false, this turnstile is lagging behind schedule, or if the calculated sleep duration is less than minTimeToCallSleep. Return the non-negative number of microseconds spent waiting, or if sleep is false, the number of microseconds the function would have had to wait.


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