5 #ifndef BITCOIN_SCHEDULER_H
6 #define BITCOIN_SCHEDULER_H
8 #include <condition_variable>
41 void schedule(Function f, std::chrono::system_clock::time_point t);
46 schedule(std::move(f), std::chrono::system_clock::now() + delta);
55 void scheduleEvery(Function f, std::chrono::milliseconds delta);
62 void MockForward(std::chrono::seconds delta_seconds);
87 size_t getQueueInfo(std::chrono::system_clock::time_point& first,
88 std::chrono::system_clock::time_point& last)
const;
96 std::multimap<std::chrono::system_clock::time_point, Function> taskQueue
GUARDED_BY(newTaskMutex);
119 std::list<std::function<void()>> m_callbacks_pending
GUARDED_BY(m_cs_callbacks_pending);
120 bool m_are_callbacks_running
GUARDED_BY(m_cs_callbacks_pending) =
false;
Class used by CScheduler clients which may schedule multiple jobs which are required to be run serial...
void scheduleEvery(Function f, std::chrono::milliseconds delta)
Repeat f until the scheduler is stopped.
void StopWhenDrained()
Tell any threads running serviceQueue to stop when there is no work left to be done.
void MaybeScheduleProcessQueue()
void MockForward(std::chrono::seconds delta_seconds)
Mock the scheduler to fast forward in time.
std::function< void()> Function
bool stopWhenEmpty GUARDED_BY(newTaskMutex)
void AddToProcessQueue(std::function< void()> func)
Add a callback to be executed.
bool stopRequested GUARDED_BY(newTaskMutex)
void stop()
Tell any threads running serviceQueue to stop as soon as the current task is done.
CScheduler * m_pscheduler
std::condition_variable newTaskScheduled
int nThreadsServicingQueue GUARDED_BY(newTaskMutex)
void schedule(Function f, std::chrono::system_clock::time_point t)
Call func at/after time t.
RecursiveMutex m_cs_callbacks_pending
SingleThreadedSchedulerClient(CScheduler *pschedulerIn)
void serviceQueue()
Services the queue 'forever'.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bool AreThreadsServicingQueue() const
Returns true if there are threads actively running in serviceQueue()
size_t getQueueInfo(std::chrono::system_clock::time_point &first, std::chrono::system_clock::time_point &last) const
Returns number of tasks waiting to be serviced, and first and last task times.
size_t CallbacksPending()
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::list< std::function< void()> > m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending)
std::multimap< std::chrono::system_clock::time_point, Function > taskQueue GUARDED_BY(newTaskMutex)
Simple class for background tasks that should be run periodically or once "after a while"...
void EmptyQueue()
Processes all remaining queue members on the calling thread, blocking until queue is empty Must be ca...
void scheduleFromNow(Function f, std::chrono::milliseconds delta)
Call f once after the delta has passed.
bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex)