8#ifndef INCLUDED_BSLMT_SEMAPHOREIMPL_COUNTED
9#define INCLUDED_BSLMT_SEMAPHOREIMPL_COUNTED
77#include <bslscm_version.h>
81#ifdef BSLMT_PLATFORM_COUNTED_SEMAPHORE
93template <
class SEMAPHORE_POLICY>
107class SemaphoreImpl<Platform::CountedSemaphore> {
113 SemaphoreImpl<Platform::CountedSemaphoreImplPolicy>
118 SemaphoreImpl(
const SemaphoreImpl&);
119 SemaphoreImpl& operator=(
const SemaphoreImpl&);
126 SemaphoreImpl(
int count);
139 void post(
int number);
152 int getValue()
const;
165SemaphoreImpl<bslmt::Platform::CountedSemaphore>::SemaphoreImpl(
173SemaphoreImpl<bslmt::Platform::CountedSemaphore>::~SemaphoreImpl()
179void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::post()
181 if (++d_resources <= 0) {
187void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::post(
int number)
189 for (
int i = 0; i < number; ++i) {
195int SemaphoreImpl<bslmt::Platform::CountedSemaphore>::tryWait()
197 for (
int i = d_resources; i > 0; i = d_resources) {
198 if (i == d_resources.testAndSwap(i, i - 1)) {
207void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::wait()
209 if (--d_resources >= 0) {
218int SemaphoreImpl<bslmt::Platform::CountedSemaphore>::getValue()
const
220 const int v = d_resources;
221 return v > 0 ? v : 0;
Definition bsls_atomic.h:744
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bslmt_barrier.h:344