6#include "Misc/Timespan.h"
7#include "Misc/AssertionMacros.h"
19 int Res = sem_init(&Semaphore, 0, InitialCount);
20 checkfSlow(Res == 0, TEXT(
"Failed to create semaphore (%d:%d): %d"), InitialCount, MaxCount, errno);
25 int Res = sem_destroy(&Semaphore);
26 checkfSlow(Res == 0, TEXT(
"Error destroying semaphore: %d"), errno);
31 int Res = sem_wait(&Semaphore);
32 checkfSlow(Res == 0, TEXT(
"Acquiring semaphore failed: %d"), errno);
38 int Res = clock_gettime(CLOCK_REALTIME, &ts);
39 checkfSlow(Res == 0, TEXT(
"clock_gettime failed: %d"), errno);
41 ts.tv_sec += (uint64)Timeout.GetTotalSeconds();
42 ts.tv_nsec += Timeout.GetFractionNano();
43 Res = sem_timedwait(&Semaphore, &ts);
44 checkfSlow(Res == 0 || Res == ETIMEDOUT, TEXT(
"sem_timedwait failed: %d"), errno);
50 checkfSlow(Count > 0, TEXT(
"Releasing semaphore with Count = %d, that should be greater than 0"), Count);
51 for (
int i = 0; i != Count; ++i)
53 int Res = sem_post(&Semaphore);
54 checkfSlow(Res == 0, TEXT(
"Releasing semaphore failed: %d"), errno);
#define checkfSlow(expr, format,...)
#define UE_NONCOPYABLE(TypeName)
FPThreadSemaphore FSemaphore
void Release(int32 Count=1)
bool TryAcquire(FTimespan Timeout=FTimespan::Zero())
FPThreadSemaphore(int32 InitialCount, int32 MaxCount)