88 std::multimap<std::chrono::steady_clock::time_point, Function>
temp_queue;
105 s.scheduleFromNow([=, &s] {
Repeat(s,
f, delta); }, delta);
114 std::chrono::steady_clock::time_point&
last)
const
147 std::function<
void()> callback;
167 instance->m_are_callbacks_running =
false;
Simple class for background tasks that should be run periodically or once "after a while".
void MockForward(std::chrono::seconds delta_seconds) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Mock the scheduler to fast forward in time.
void serviceQueue() EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Services the queue 'forever'.
void scheduleEvery(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Repeat f until the scheduler is stopped.
size_t getQueueInfo(std::chrono::steady_clock::time_point &first, std::chrono::steady_clock::time_point &last) const EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Returns number of tasks waiting to be serviced, and first and last task times.
std::function< void()> Function
bool AreThreadsServicingQueue() const EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Returns true if there are threads actively running in serviceQueue()
bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex)
std::condition_variable newTaskScheduled
void scheduleFromNow(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Call f once after the delta has passed.
void schedule(Function f, std::chrono::steady_clock::time_point t) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Call func at/after time t.
Class used by CScheduler clients which may schedule multiple jobs which are required to be run serial...
void MaybeScheduleProcessQueue() EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
void ProcessQueue() EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
size_t size() override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
Returns the number of currently pending events.
void insert(std::function< void()> func) override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
Add a callback to be executed.
void flush() override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
Processes all remaining queue members on the calling thread, blocking until queue is empty Must be ca...
static void Repeat(CScheduler &s, CScheduler::Function f, std::chrono::milliseconds delta)
#define WAIT_LOCK(cs, name)
#define REVERSE_LOCK(g, cs)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.