[#BloombergLP-bslmt-FastPostSemaphoreImpl] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::FastPostSemaphoreImpl :relfileprefix: ../../ :mrdocs: This class implements a semaphore type, optimized for `post`, for thread synchronization. == Synopsis Declared in `<bslmt_fastpostsemaphoreimpl.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class ATOMIC_OP, class MUTEX, class CONDITION, class THREADUTIL> class FastPostSemaphoreImpl; ---- == Enums [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/ReturnValue.adoc[`ReturnValue`] | Status codes returned by semaphore operations. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/2constructor-09.adoc[`FastPostSemaphoreImpl`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/clockType.adoc[`clockType`] | Return the clock type used for timeouts. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/disable.adoc[`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. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/enable.adoc[`enable`] | Enable waiting on this semaphore. If the semaphore is initially enabled, this call has no effect. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/getDisabledState.adoc[`getDisabledState`] | 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. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/getValue.adoc[`getValue`] | Return the current value (`count > 0 ? count : 0`) of this semaphore. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/getValueRaw.adoc[`getValueRaw`] | Return the current value (`count`) of this semaphore. Note that, unlike `getValue`, this method can return a negative value. Also note that this method is principally intended for use in testing. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/isDisabled.adoc[`isDisabled`] | Return `true` if this semaphore is wait disabled, and `false` otherwise. Note that the semaphore is created in the "wait enabled" state. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/post-03.adoc[`post`] | `post` overloads | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/postWithRedundantSignal.adoc[`postWithRedundantSignal`] | 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. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/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. Otherwise, do nothing and return 0. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/takeAll.adoc[`takeAll`] | 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. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/timedWait.adoc[`timedWait`] | 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). | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/tryWait.adoc[`tryWait`] | 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. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/wait.adoc[`wait`] | 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. |=== == Static Data Members [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_AVAILABLE_INC.adoc[`k_AVAILABLE_INC`] | Increment value for the available count in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_AVAILABLE_MASK.adoc[`k_AVAILABLE_MASK`] | Mask for the available‐count field in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_AVAILABLE_SHIFT.adoc[`k_AVAILABLE_SHIFT`] | Bit shift for the available‐count field in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_BLOCKED_INC.adoc[`k_BLOCKED_INC`] | Increment value for the blocked‐thread count in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_BLOCKED_MASK.adoc[`k_BLOCKED_MASK`] | Mask for the blocked‐thread count field in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_DISABLED_GEN_INC.adoc[`k_DISABLED_GEN_INC`] | Increment value for the disabled‐generation count in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_DISABLED_GEN_MASK.adoc[`k_DISABLED_GEN_MASK`] | Mask for the disabled‐generation field in `d_state`. | xref:BloombergLP/bslmt/FastPostSemaphoreImpl/k_DISABLED_GEN_SHIFT.adoc[`k_DISABLED_GEN_SHIFT`] | Bit shift for the disabled‐generation field in `d_state`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#