RunLoopSynchronizer#

Fully qualified name: omni::kit::RunLoopSynchronizer

class RunLoopSynchronizer#

Class for synchronizing multiple run loops.

Provides functionality to synchronize multiple threads or run loops to a common timing source, typically the present/render thread. Supports frame rate control and timing adjustments.

Public Functions

RunLoopSynchronizer()#
~RunLoopSynchronizer()#
void presentPreNotify()#

Saves the present time and duration.

void presentPostNotify()#

Notifies the condition variable in wait that it has to wake up.

Saves the syncronization point.

void wait(
float alreadyPassedNs,
size_t slidingMaximumCount,
size_t slidingMaximumOutlierCount,
float slidingMaximumToleranceFactor,
)#

Waits for the present thread and syncs the calling thread to the present thread.

This function calculates how long it needs to wait using a Sliding Maximum of the already passed time. It uses a high resolution clock to wait until the desired frame duration is met. It starts by obtaining the current time, and calculates the sliding maximum of the already passed time, ignoring a specified number of outliers. The function then determines if waiting is necessary by comparing the current time with the computed time point it should wake up at.

Parameters:
  • alreadyPassedNs – The duration in nanoseconds that has already passed.

  • slidingMaximumCount – The number of recent durations to consider when finding the sliding maximum.

  • slidingMaximumOutlierCount – The number of outlier durations to ignore when finding the sliding maximum.

  • slidingMaximumToleranceFactor – A multiplier for the average duration. Durations exceeding this are considered outliers.

void setTargetFPS(double fps)#

Sets the target frames per second.

Parameters:

fps[in] Desired frame rate in frames per second

bool isActive() const#

Checks if the synchronizer is active.

Returns:

True if synchronization is active, false otherwise

void setActive(bool active)#

Enables or disables synchronization.

Parameters:

active[in] True to enable synchronization, false to disable