3#include <Common/config.h>
4#include <Common/primitive_type.h>
11#include <condition_variable>
23 using Work = std::function<void()>;
74 void asyncProcessWork();
79 bool isWorkerThread()
const;
82#if PH_ENSURE_LOCKFREE_ALGORITHMS_ARE_LOCKLESS
83 static_assert(std::atomic<uint64>::is_always_lock_free);
87 std::vector<Work> m_works;
88 std::mutex m_executorMutex;
89 std::condition_variable m_workerCv;
91 bool m_isTerminationRequested;
92 std::atomic<uint64> m_periodMs;
99 m_periodMs.store(periodMs, std::memory_order_relaxed);
102inline bool PeriodicSingleThreadExecutor::isWorkerThread()
const
104 return std::this_thread::get_id() == m_worker.get_id();
A single-thread executor that runs specified works periodically. The executor can be used concurrentl...
Definition PeriodicSingleThreadExecutor.h:21
void addWork(const Work &work)
Add a work to the executor. Work will not start until calling resume().
Definition PeriodicSingleThreadExecutor.cpp:38
void setPeriodMs(uint64 periodMs)
Sets execution period of the executor in milliseconds. The new period will take effect within finite ...
Definition PeriodicSingleThreadExecutor.h:97
PeriodicSingleThreadExecutor(uint64 periodMs)
Create an executor in the paused state.
Definition PeriodicSingleThreadExecutor.cpp:12
void requestTermination()
Stop the executor. Worker will stop processing any work as soon as possible. Any work that is already...
Definition PeriodicSingleThreadExecutor.cpp:134
std::function< void()> Work
Definition PeriodicSingleThreadExecutor.h:23
void pause()
Pause the execution. Should not be called on worker thread.
Definition PeriodicSingleThreadExecutor.cpp:110
void resume()
Resume the execution. Should not be called on worker thread.
Definition PeriodicSingleThreadExecutor.cpp:120
~PeriodicSingleThreadExecutor()
Terminate the execution. Wait for any ongoing work to finish.
Definition PeriodicSingleThreadExecutor.cpp:27
The root for all renderer implementations.
Definition EEngineProject.h:6