UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::TEventCount< CounterType > Class Template Reference

#include <EventCount.h>

Public Member Functions

constexpr TEventCount ()=default
 
 TEventCount (const TEventCount &)=delete
 
TEventCountoperator= (const TEventCount &)=delete
 
TEventCountToken< CounterTypePrepareWait ()
 
void Wait (TEventCountToken< CounterType > Compare)
 
bool WaitFor (TEventCountToken< CounterType > Compare, FMonotonicTimeSpan WaitTime)
 
bool WaitUntil (TEventCountToken< CounterType > Compare, FMonotonicTimePoint WaitTime)
 
void Notify ()
 
void NotifyWeak ()
 

Detailed Description

template<typename CounterType>
class UE::TEventCount< CounterType >

A type of event that avoids missed notifications by maintaining a notification count.

This type of event is suited to waiting on another thread conditionally. Typical usage looks similar to this example:

FEventCount Event;
std::atomic<uint32> CurrentValue = 0;

On the waiting thread:

FEventCountToken Token = Event.PrepareWait();
if (CurrentValue < TargetValue)
{
    Event.Wait(Token);
}

On the notifying thread:

if (++CurrentValue == TargetValue)
{
    Event.Notify();
}

Acquiring a token before checking the condition avoids a race because Wait returns immediately when the token no longer matches the notification count.

Constructor & Destructor Documentation

◆ TEventCount() [1/2]

template<typename CounterType >
constexpr UE::TEventCount< CounterType >::TEventCount ( )
constexprdefault

◆ TEventCount() [2/2]

template<typename CounterType >
UE::TEventCount< CounterType >::TEventCount ( const TEventCount< CounterType > &  )
delete

Member Function Documentation

◆ Notify()

template<typename CounterType >
void UE::TEventCount< CounterType >::Notify ( )
inline

Notifies all waiting threads.

Any threads that have called PrepareWait() and not yet waited will be notified immediately if they do wait on a token from a call to PrepareWait() that preceded this call.

◆ NotifyWeak()

template<typename CounterType >
void UE::TEventCount< CounterType >::NotifyWeak ( )
inline

Notifies all waiting threads.

Any threads that have called PrepareWait() and not yet waited will be notified immediately if they do wait on a token from a call to PrepareWait() that preceded this call. Note: This version doesn't provide a memory barrier, you are responsible for the memory ordering for the value you're synchronizing this eventcount with.

◆ operator=()

template<typename CounterType >
TEventCount & UE::TEventCount< CounterType >::operator= ( const TEventCount< CounterType > &  )
delete

◆ PrepareWait()

template<typename CounterType >
TEventCountToken< CounterType > UE::TEventCount< CounterType >::PrepareWait ( )
inline

Prepare to wait.

Call this before any logic that must re-execute if the event is notified in the meantime.

Returns
A token to pass to one of the wait functions to abort the wait if the event has been notified since.

◆ Wait()

template<typename CounterType >
void UE::TEventCount< CounterType >::Wait ( TEventCountToken< CounterType Compare)
inline

Wait until the event is notified. Returns immediately if notified since the token was acquired.

Parameters
CompareA token acquired from PrepareWait() before checking the conditions for this wait.

◆ WaitFor()

template<typename CounterType >
bool UE::TEventCount< CounterType >::WaitFor ( TEventCountToken< CounterType Compare,
FMonotonicTimeSpan  WaitTime 
)
inline

Wait until the event is notified. Returns immediately if notified since the token was acquired.

Parameters
CompareA token acquired from PrepareWait() before checking the conditions for this wait.
WaitTimeRelative time after which waiting is automatically canceled and the thread wakes.
Returns
True if the event was notified before the wait time elapsed, otherwise false.

◆ WaitUntil()

template<typename CounterType >
bool UE::TEventCount< CounterType >::WaitUntil ( TEventCountToken< CounterType Compare,
FMonotonicTimePoint  WaitTime 
)
inline

Wait until the event is notified. Returns immediately if notified since the token was acquired.

Parameters
CompareA token acquired from PrepareWait() before checking the conditions for this wait.
WaitTimeAbsolute time after which waiting is automatically canceled and the thread wakes.
Returns
True if the event was notified before the wait time elapsed, otherwise false.

The documentation for this class was generated from the following file: