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>
|
using | Work = std::function<void()> |
|
|
| 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) |
|
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.
◆ Work
◆ 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.
◆ 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: