[#BloombergLP-bslmt-Turnstile]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::Turnstile
:relfileprefix: ../../
:mrdocs:

This class provides a mechanism to meter time&period; Using either the constructor or the `reset` method, the client specifies `rate`, indicating the number of events per second that the turnstile will allow&period; 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&period; 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&period; Note that calling `waitTurn` a single time does not bring a turnstile back on schedule&period; For example, if a turnstile&apos;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&period; 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&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;turnstile&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class Turnstile;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/Turnstile/2constructor.adoc[`Turnstile`]         [.small]#[constructor]#
| Create a turnstile object that admits clients at the specified `rate`, expressed as the number of turns per second&period; Optionally specify the (relative) `startTime` of the first turn&period; If `startTime` is not specified, the first turn may be taken immediately&period; Optionally specify `minTimeToCallSleep`, the shortest period of time in seconds that the `waitTurn` function will go to sleep&period; The behavior is undefined unless `0 &lt; rate`&period;
| xref:BloombergLP/bslmt/Turnstile/lagTime.adoc[`lagTime`] 
| 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&period; Otherwise, return 0&period;
| xref:BloombergLP/bslmt/Turnstile/reset.adoc[`reset`] 
| Reset the rate of this turnstile to the specified `rate`, expressed as the number of turns per second&period; Optionally specify the (relative) `startTime` of the first turn&period; If `startTime` is not specified, the first turn may be taken immediately&period; Optionally specify `minTimeToCallSleep`, the shortest period of time in seconds that the `waitTurn` function will go to sleep&period; The behavior is undefined unless `0 &lt; rate`&period; Note that threads blocked on `waitTurn` are not interrupted&period;
| xref:BloombergLP/bslmt/Turnstile/waitTurn.adoc[`waitTurn`] 
| 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`&period; Return the non&hyphen;negative number of microseconds spent waiting, or if `sleep` is false, the number of microseconds the function would have had to wait&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
