40 return (EventLoopThreadId != 0);
60 return bShutdownRequested;
69template <
typename IOManagerType,
typename Traits = FEventLoopDefaultTraits>
93 : IOManager(*this,
MoveTemp(Params.IOManagerParams))
97 , EventLoopThreadId(0)
98 , bShutdownRequested(
false)
99 , bShutdownCompleted(
false)
100 , bNotifyOnInit(
false)
103 static_assert(std::is_base_of_v<IIOManager, IOManagerType> ==
true);
112 return IOManager.GetIOAccess();
126 Traits::CheckNotInitialized(EventLoopThreadId);
127 LoopTime = Traits::GetCurrentTime();
130 EventLoopThreadId = Traits::GetCurrentThreadId();
146 ShutdownMutex.
Lock();
161 else if (!bShutdownCompleted)
199 virtual void Run()
override
202 Traits::CheckInitialized(EventLoopThreadId);
219 Traits::CheckInitialized(EventLoopThreadId);
221 if (bShutdownCompleted)
235 IOManager.Poll(WaitTime);
238 FTimespan CurrentTime = Traits::GetCurrentTime();
239 FTimespan ElapsedTime = FMath::Max(CurrentTime - LoopTime, 0.0);
240 LoopTime = CurrentTime;
241 TimerManager.
Tick(ElapsedTime);
248 CurrentTime = Traits::GetCurrentTime();
249 ElapsedTime = FMath::Max(CurrentTime - LoopTime, 0.0);
250 LoopTime = CurrentTime;
251 TimerManager.
Tick(ElapsedTime);
256 if (Traits::IsShutdownRequested(bShutdownRequested))
258 IOManager.Shutdown();
262 ShutdownMutex.
Lock();
268 bShutdownCompleted =
true;
290 Traits::CheckInitialized(EventLoopThreadId);
306 if (Traits::IsInitialized(EventLoopThreadId))
319 if (!Traits::IsInitialized(EventLoopThreadId))
323 bNotifyOnInit =
true;
#define check(expr)
Definition AssertionMacros.h:314
void AsyncTask(ENamedThreads::Type Thread, TUniqueFunction< void()> Function)
Definition Async.cpp:54
#define QUICK_SCOPE_CYCLE_COUNTER(Stat)
Definition Stats.h:652
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ON_SCOPE_EXIT
Definition ScopeExit.h:73
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition MpscQueue.h:18
TOptional< ElementType > Dequeue()
Definition MpscQueue.h:58
void Enqueue(ArgTypes &&... Args)
Definition MpscQueue.h:49
Definition IEventLoop.h:26
Definition EventLoop.h:71
virtual void ClearTimer(FTimerHandle &InHandle, FOnTimerCleared &&OnTimerCleared=FOnTimerCleared()) override
Definition EventLoop.h:187
virtual ~TEventLoop()
Definition EventLoop.h:106
virtual FTimespan GetLoopTime() const override
Definition EventLoop.h:288
virtual bool RunOnce(FTimespan WaitTime) override
Definition EventLoop.h:216
virtual FTimerHandle SetTimer(FTimerCallback &&Callback, FTimespan InRate, bool InbRepeat=false, TOptional< FTimespan > InFirstDelay=TOptional< FTimespan >()) override
Definition EventLoop.h:180
virtual bool Init() override
Definition EventLoop.h:115
TEventLoop(FParams &&Params=FParams())
Definition EventLoop.h:92
IOManagerType::FIOAccess & GetIOAccess()
Definition EventLoop.h:110
virtual void Run() override
Definition EventLoop.h:199
virtual void PostAsyncTask(FAsyncTask &&Task) override
Definition EventLoop.h:193
virtual void RequestShutdown(FOnShutdownComplete &&OnShutdownComplete=FOnShutdownComplete()) override
Definition EventLoop.h:141
Definition EventLoopTimer.h:133
void Init()
Definition EventLoopTimer.h:146
bool GetNextTimeout(FTimespan &OutTimeout) const
Definition EventLoopTimer.h:168
FTimerHandle SetTimer(FTimerCallback &&Callback, FTimespan InRate, bool InbRepeat=false, TOptional< FTimespan > InFirstDelay=TOptional< FTimespan >())
Definition EventLoopTimer.h:205
bool HasPendingRepeatTimer() const
Definition EventLoopTimer.h:260
void Tick(FTimespan DeltaTime)
Definition EventLoopTimer.h:311
void ClearTimer(FTimerHandle &InHandle, FOnTimerCleared &&OnTimerCleared=FOnTimerCleared())
Definition EventLoopTimer.h:234
void Lock()
Definition Mutex.h:43
void Unlock()
Definition Mutex.h:53
void ForEach(InT &&Input, CallableT Callable)
Definition ForEach.h:36
constexpr int64 TicksPerSecond
Definition Timespan.h:47
Definition EventLoopLog.cpp:5
TUniqueFunction< void()> FOnShutdownComplete
Definition IEventLoop.h:23
FManagedStorageOnRemoveComplete FOnTimerCleared
Definition EventLoopTimer.h:20
@ false
Definition radaudio_common.h:23
static uint32 GetCurrentThreadId(void)
Definition AndroidPlatformTLS.h:20
static double Seconds()
Definition AndroidPlatformTime.h:20
Definition Optional.h:131
Definition EventLoop.h:65
Definition EventLoop.h:22
static void CheckIsEventLoopThread(uint32 EventLoopThreadId)
Definition EventLoop.h:53
static void CheckInitialized(uint32 EventLoopThreadId)
Definition EventLoop.h:43
static bool IsInitialized(uint32 EventLoopThreadId)
Definition EventLoop.h:38
static void CheckNotInitialized(uint32 EventLoopThreadId)
Definition EventLoop.h:48
static uint32 GetCurrentThreadId()
Definition EventLoop.h:23
static bool IsShutdownRequested(bool bShutdownRequested)
Definition EventLoop.h:58
static bool IsEventLoopThread(uint32 EventLoopThreadId)
Definition EventLoop.h:33
static FTimespan GetCurrentTime()
Definition EventLoop.h:28
Definition EventLoopTimer.h:100
Definition EventLoop.h:87
IOManagerType::FParams IOManagerParams
Definition EventLoop.h:89
Definition EventLoopHandle.h:12