UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GenericPlatformManualResetEvent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "HAL/PlatformMath.h"
8
9#include <atomic>
10#include <chrono>
11#include <condition_variable>
12#include <mutex>
13
14namespace UE::HAL::Private
15{
16
24{
25public:
29
36 void Reset()
37 {
38 std::unique_lock SelfLock(Lock);
39 bWait = true;
40 }
41
47 bool Poll()
48 {
49 std::unique_lock SelfLock(Lock);
50 return !bWait;
51 }
52
58 void Wait()
59 {
60 LowLevelTasks::FOversubscriptionScope _;
61 std::unique_lock SelfLock(Lock);
62 Condition.wait(SelfLock, [this] { return !bWait; });
63 }
64
74 {
75 if (WaitTime.IsInfinity())
76 {
77 Wait();
78 return true;
79 }
80
81 if (WaitTime <= FMonotonicTimeSpan::Zero())
82 {
83 std::unique_lock SelfLock(Lock);
84 return !bWait;
85 }
86
87 LowLevelTasks::FOversubscriptionScope _;
88 std::unique_lock SelfLock(Lock);
89 const int64 WaitMs = FPlatformMath::CeilToInt64(WaitTime.ToMilliseconds());
90 return Condition.wait_for(SelfLock, std::chrono::milliseconds(WaitMs), [this] { return !bWait; });
91 }
92
102 {
103 return WaitFor(WaitTime - FMonotonicTimePoint::Now());
104 }
105
112 void Notify()
113 {
114 // The lock must be held by Notify() until it is finished accessing its members, otherwise a waiting thread
115 // may destroy the event after its wait but before Notify() has finished.
116 std::unique_lock SelfLock(Lock);
117 bWait = false;
118 Condition.notify_one();
119 }
120
121private:
122 std::mutex Lock;
123 std::condition_variable Condition;
124 bool bWait = true;
125};
126
127} // UE::HAL::Private
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition GenericPlatformManualResetEvent.h:24
void Wait()
Definition GenericPlatformManualResetEvent.h:58
FGenericPlatformManualResetEvent(const FGenericPlatformManualResetEvent &)=delete
bool Poll()
Definition GenericPlatformManualResetEvent.h:47
bool WaitUntil(FMonotonicTimePoint WaitTime)
Definition GenericPlatformManualResetEvent.h:101
void Reset()
Definition GenericPlatformManualResetEvent.h:36
void Notify()
Definition GenericPlatformManualResetEvent.h:112
FGenericPlatformManualResetEvent & operator=(const FGenericPlatformManualResetEvent &)=delete
bool WaitFor(FMonotonicTimeSpan WaitTime)
Definition GenericPlatformManualResetEvent.h:73
Definition AndroidPlatformManualResetEvent.cpp:14
Definition MonotonicTime.h:74
static UE_API FMonotonicTimePoint Now()
Definition MonotonicTime.cpp:10
Definition MonotonicTime.h:20
static constexpr FMonotonicTimeSpan Zero()
Definition MonotonicTime.h:24
constexpr double ToMilliseconds() const
Definition MonotonicTime.h:38
constexpr bool IsInfinity() const
Definition MonotonicTime.h:41