Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::PeriodicSingleThreadExecutor Class Referencefinal

A single-thread executor that runs specified works periodically. The executor can be used concurrently, namely, it is thread-safe. However, the user must ensure that the pool is properly initialized before subsequent usages. More...

#include <PeriodicSingleThreadExecutor.h>

Public Types

using Work = std::function<void()>
 

Public Member Functions

 PeriodicSingleThreadExecutor (uint64 periodMs)
 Create an executor in the paused state.
 
 ~PeriodicSingleThreadExecutor ()
 Terminate the execution. Wait for any ongoing work to finish.
 
void setPeriodMs (uint64 periodMs)
 Sets execution period of the executor in milliseconds. The new period will take effect within finite amount of time (as soon as possible).
 
void pause ()
 Pause the execution. Should not be called on worker thread.
 
void resume ()
 Resume the execution. Should not be called on worker thread.
 
void requestTermination ()
 Stop the executor. Worker will stop processing any work as soon as possible. Any work that is already being processed will still complete. Paused state will be resumed and terminate. No further write operations should be performed after requesting termination. Requesting termination multiple times has the same effect.
 
void addWork (const Work &work)
 Add a work to the executor. Work will not start until calling resume().
 
void addWork (Work &&work)
 

Detailed Description

A single-thread executor that runs specified works periodically. The executor can be used concurrently, namely, it is thread-safe. However, the user must ensure that the pool is properly initialized before subsequent usages.

Member Typedef Documentation

◆ Work

using ph::PeriodicSingleThreadExecutor::Work = std::function<void()>

Constructor & Destructor Documentation

◆ PeriodicSingleThreadExecutor()

ph::PeriodicSingleThreadExecutor::PeriodicSingleThreadExecutor ( uint64 periodMs)
explicit

Create an executor in the paused state.

◆ ~PeriodicSingleThreadExecutor()

ph::PeriodicSingleThreadExecutor::~PeriodicSingleThreadExecutor ( )

Terminate the execution. Wait for any ongoing work to finish.

Member Function Documentation

◆ addWork() [1/2]

void ph::PeriodicSingleThreadExecutor::addWork ( const Work & work)

Add a work to the executor. Work will not start until calling resume().

Note
Thread-safe.

◆ addWork() [2/2]

void ph::PeriodicSingleThreadExecutor::addWork ( Work && work)

◆ pause()

void ph::PeriodicSingleThreadExecutor::pause ( )

Pause the execution. Should not be called on worker thread.

Note
Thread-safe.

◆ requestTermination()

void ph::PeriodicSingleThreadExecutor::requestTermination ( )

Stop the executor. Worker will stop processing any work as soon as possible. Any work that is already being processed will still complete. Paused state will be resumed and terminate. No further write operations should be performed after requesting termination. Requesting termination multiple times has the same effect.

Note
Thread-safe.

◆ resume()

void ph::PeriodicSingleThreadExecutor::resume ( )

Resume the execution. Should not be called on worker thread.

Note
Thread-safe.

◆ setPeriodMs()

void ph::PeriodicSingleThreadExecutor::setPeriodMs ( uint64 periodMs)
inline

Sets execution period of the executor in milliseconds. The new period will take effect within finite amount of time (as soon as possible).

Note
Thread-safe.

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