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

This class implements a semaphore type, optimized for `post`, for thread synchronization&period;

== Synopsis

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

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

== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/FastPostSemaphore/ReturnValue.adoc[`ReturnValue`] 
| Status codes returned by semaphore operations&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/FastPostSemaphore/2constructor-0f.adoc[`FastPostSemaphore`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bslmt/FastPostSemaphore/clockType.adoc[`clockType`] 
| Return the clock type used for timeouts&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/disable.adoc[`disable`] 
| Disable waiting on this semaphore&period; All subsequent invocations of `wait`, `tryWait`, and `timedWait` will fail immediately&period; All blocked invocations of `wait` and `timedWait` will fail immediately&period; If the semaphore is already disabled, this method will have no effect&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/enable.adoc[`enable`] 
| Enable waiting on this semaphore&period; If the semaphore is not disabled, this call has no effect&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/getDisabledState.adoc[`getDisabledState`] 
| Return an odd value if this semaphore is wait disabled, and an even value otherwise&period; 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&period; For example, for any initial state of a semaphore instance `obj`&colon; &grave; int state &equals; obj&period;getDisabledState()&semi; obj&period;disable()&semi; obj&period;enable()&semi; ASSERT(state !&equals; obj&period;getDisabledState())&semi; &grave; This functionality is useful in higher&hyphen;level components to determine if this semaphore was disabled during an operation&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/getValue.adoc[`getValue`] 
| Return the current value (`count &gt; 0 ? count &colon; 0`) of this semaphore&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/isDisabled.adoc[`isDisabled`] 
| Return `true` if this semaphore is wait disabled, and `false` otherwise&period; Note that the semaphore is created in the &quot;wait enabled&quot; state&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/post-0c.adoc[`post`] 
| `post` overloads
| xref:BloombergLP/bslmt/FastPostSemaphore/postWithRedundantSignal.adoc[`postWithRedundantSignal`] 
| Atomically increase the count of this semaphore by the specified `value`&period; 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)&period; The behavior is undefined unless `value &gt; 0`&period; Note that this method is provided to help mitigate issues in the implementation of underlying synchronization primitives&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/take.adoc[`take`] 
| 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&period; Otherwise, do nothing and return 0&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/takeAll.adoc[`takeAll`] 
| If the count of this semaphore is positive, reduce the count to 0 and return the original value of the count&period; Otherwise, do nothing and return 0&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/timedWait-02.adoc[`timedWait`] 
| `timedWait` overloads
| xref:BloombergLP/bslmt/FastPostSemaphore/tryWait.adoc[`tryWait`] 
| If this semaphore is initially disabled, return `e&lowbar;DISABLED` with no effect on the count&period; Otherwise, if the count of this semaphore is a positive value, return 0 and atomically decrement the count&period; If this semaphore is not disabled and the count of this semaphore is not a positive value, return `e&lowbar;WOULD&lowbar;BLOCK` with no effect on the count&period;
| xref:BloombergLP/bslmt/FastPostSemaphore/wait.adoc[`wait`] 
| If this semaphore is initially disabled, or becomes disabled while blocking, return `e&lowbar;DISABLED` with no effect on the count&period; Otherwise, block until the count of this semaphore is a positive value, return 0 and atomically decrement the count&period; Return `e&lowbar;FAILED` if an error occurs&period;
|===



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