8#ifndef INCLUDED_BSLMT_SEMAPHOREIMPL_WIN32
9#define INCLUDED_BSLMT_SEMAPHOREIMPL_WIN32
68#include <bslscm_version.h>
72#ifdef BSLMT_PLATFORM_WIN32_THREADS
79#include <bsl_c_limits.h>
81struct _SECURITY_ATTRIBUTES;
82typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
83typedef struct _SECURITY_ATTRIBUTES *LPSECURITY_ATTRIBUTES;
84typedef long LONG, *LPLONG;
87typedef const char *LPCSTR;
88typedef unsigned long DWORD;
92 __declspec(dllimport) HANDLE __stdcall CreateSemaphoreA(
93 LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
99 __declspec(dllimport) BOOL __stdcall CloseHandle(
103 __declspec(dllimport) BOOL __stdcall ReleaseSemaphore(
106 LPLONG lpPreviousCount
109 __declspec(dllimport) DWORD __stdcall WaitForSingleObject(
119template <
class SEMAPHORE_POLICY>
130class SemaphoreImpl<Platform::Win32Semaphore> {
142 SemaphoreImpl(
const SemaphoreImpl&);
143 SemaphoreImpl& operator=(
const SemaphoreImpl&);
151 SemaphoreImpl(
int count);
163 void post(
int number);
176 int getValue()
const;
189SemaphoreImpl<bslmt::Platform::Win32Semaphore>::SemaphoreImpl(
int count)
195 d_handle = CreateSemaphoreA(NULL, 0, INT_MAX, NULL);
196 if (NULL == d_handle) {
202SemaphoreImpl<bslmt::Platform::Win32Semaphore>::~SemaphoreImpl()
204 CloseHandle(d_handle);
209void SemaphoreImpl<bslmt::Platform::Win32Semaphore>::post()
211 if (++d_resources <= 0) {
212 ReleaseSemaphore(d_handle, 1, NULL);
217void SemaphoreImpl<bslmt::Platform::Win32Semaphore>::wait()
219 if (--d_resources >= 0) {
222 WaitForSingleObject(d_handle, 0xFFFFFFFF );
227int SemaphoreImpl<bslmt::Platform::Win32Semaphore>::getValue()
const
229 const int v = d_resources;
230 return v > 0 ? v : 0;
Definition bsls_atomic.h:743
#define BSLS_ASSERT_INVOKE_NORETURN(X)
Definition bsls_assert.h:1895
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344