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> {
143 SemaphoreImpl(
const SemaphoreImpl&);
144 SemaphoreImpl& operator=(
const SemaphoreImpl&);
152 SemaphoreImpl(
int count);
165 void post(
int number);
178 int getValue()
const;
191SemaphoreImpl<bslmt::Platform::Win32Semaphore>::SemaphoreImpl(
int count)
197 d_handle = CreateSemaphoreA(NULL, 0, INT_MAX, NULL);
198 if (NULL == d_handle) {
204SemaphoreImpl<bslmt::Platform::Win32Semaphore>::~SemaphoreImpl()
206 CloseHandle(d_handle);
211void SemaphoreImpl<bslmt::Platform::Win32Semaphore>::post()
213 if (++d_resources <= 0) {
214 ReleaseSemaphore(d_handle, 1, NULL);
219void SemaphoreImpl<bslmt::Platform::Win32Semaphore>::wait()
221 if (--d_resources >= 0) {
224 WaitForSingleObject(d_handle, 0xFFFFFFFF );
229int SemaphoreImpl<bslmt::Platform::Win32Semaphore>::getValue()
const
231 const int v = d_resources;
232 return v > 0 ? v : 0;
Definition bsls_atomic.h:744
#define BSLS_ASSERT_INVOKE_NORETURN(X)
Definition bsls_assert.h:2101
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bslmt_barrier.h:344