UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MacSemaphore.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Misc/Timespan.h"
8
9#include <dispatch/dispatch.h>
10
12{
13public:
15
18 {
19 checkfSlow(InitialCount >= 0, TEXT("Semaphore's initial count must be non negative value: %d"), InitialCount);
20 }
21
23 {
24 dispatch_release(Semaphore);
25 }
26
27 void Acquire()
28 {
30 checkfSlow(Res == 0, TEXT("Acquiring semaphore failed"));
31 }
32
34 {
35 dispatch_time_t TS = dispatch_time(DISPATCH_TIME_NOW, (int64)Timeout.GetTotalMicroseconds() * 1000);
36 intptr_t Res = dispatch_semaphore_wait(Semaphore, TS);
37 return Res == 0;
38 }
39
41 {
42 checkfSlow(Count > 0, TEXT("Releasing semaphore with Count = %d, that should be greater than 0"), Count);
43 for (int i = 0; i != Count; ++i)
44 {
46 }
47 }
48
49private:
50 dispatch_semaphore_t Semaphore;
51};
52
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FMacSemaphore FSemaphore
Definition MacSemaphore.h:53
Definition MacSemaphore.h:12
FMacSemaphore(int32 InitialCount, int32)
Definition MacSemaphore.h:16
void Release(int32 Count=1)
Definition MacSemaphore.h:40
virtual ~FMacSemaphore()
Definition MacSemaphore.h:22
void Acquire()
Definition MacSemaphore.h:27
UE_NONCOPYABLE(FMacSemaphore)
bool TryAcquire(FTimespan Timeout=FTimespan::Zero())
Definition MacSemaphore.h:33
Definition Timespan.h:76
static FTimespan Zero()
Definition Timespan.h:747