6#include "Misc/Timespan.h"
7#include "Misc/AssertionMacros.h"
8#include "Windows/WindowsHWrapper.h"
9#include "Windows/AllowWindowsPlatformTypes.h"
11class FWindowsSemaphore
16 FWindowsSemaphore(int32 InitialCount, int32 MaxCount)
17 : Semaphore(CreateSemaphore(
nullptr, InitialCount, MaxCount,
nullptr))
19 checkfSlow(Semaphore, TEXT(
"CreateSemaphore failed: %u"), GetLastError());
24 CloseHandle(Semaphore);
29 DWORD Res = WaitForSingleObject(Semaphore, INFINITE);
30 checkfSlow(Res == WAIT_OBJECT_0, TEXT(
"Acquiring semaphore failed: %d (%u)"), Res, GetLastError());
33 bool TryAcquire(FTimespan Timeout = FTimespan::Zero())
35 DWORD Res = WaitForSingleObject(Semaphore, (DWORD)Timeout.GetTotalMilliseconds());
36 checkfSlow(Res == WAIT_OBJECT_0 || Res == WAIT_TIMEOUT, TEXT(
"Acquiring semaphore failed: %d (%u)"), Res, GetLastError());
37 return Res == WAIT_OBJECT_0;
40 void Release(int32 Count = 1)
42 checkfSlow(Count > 0, TEXT(
"Releasing semaphore with Count = %d, that should be greater than 0"), Count);
43 bool bRes = ReleaseSemaphore(Semaphore, Count,
nullptr);
44 checkfSlow(bRes, TEXT(
"Releasing semaphore for %d failed: %u"), Count, GetLastError());
51using FSemaphore = FWindowsSemaphore;
53#include "Windows/HideWindowsPlatformTypes.h"
#define checkfSlow(expr, format,...)
#define UE_NONCOPYABLE(TypeName)