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>
117 SemaphoreImpl(
const SemaphoreImpl&);
118 SemaphoreImpl& operator=(
const SemaphoreImpl&);
125 SemaphoreImpl(
int count);
137 void post(
int number);
150 int getValue()
const;
163SemaphoreImpl<bslmt::Platform::CountedSemaphore>::SemaphoreImpl(
171SemaphoreImpl<bslmt::Platform::CountedSemaphore>::~SemaphoreImpl()
177void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::post()
179 if (++d_resources <= 0) {
185void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::post(
int number)
187 for (
int i = 0; i < number; ++i) {
193int SemaphoreImpl<bslmt::Platform::CountedSemaphore>::tryWait()
195 for (
int i = d_resources; i > 0; i = d_resources) {
196 if (i == d_resources.testAndSwap(i, i - 1)) {
205void SemaphoreImpl<bslmt::Platform::CountedSemaphore>::wait()
207 if (--d_resources >= 0) {
216int SemaphoreImpl<bslmt::Platform::CountedSemaphore>::getValue()
const
218 const int v = d_resources;
219 return v > 0 ? v : 0;
Definition bsls_atomic.h:743
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344