26 #ifndef THREADEDDISPATCHER_H
27 #define THREADEDDISPATCHER_H
29 #include <IDispatcher.h>
32 #include <condition_variable>
52 virtual void post(std::function<
void ()> work)
final;
58 virtual void sync()
final;
96 void doWork(
const std::string& name,
int priority);
103 inline std::function<void ()>
next();
106 std::condition_variable cv;
108 std::deque<std::function<void ()>> q;
A dispatcher interface.
Definition: IDispatcher.h:41
A dispatcher that does all the work on a single, separate thread started in constructor.
Definition: ThreadedDispatcher.h:46
void stop()
Cancels any work that is not already in progress, stop accepting new work.
Definition: ThreadedDispatcher.cpp:163
std::function< void()> next()
Returns next work item.
Definition: ThreadedDispatcher.cpp:211
virtual void post(std::function< void()> work) final
Definition: ThreadedDispatcher.cpp:41
virtual void sync() final
Ensures that anything that was in the queue before the call has been executed before returning.
Definition: ThreadedDispatcher.cpp:106
void flush()
Perform any work remaining in the queue, then stop accepting new work.
Definition: ThreadedDispatcher.cpp:141
bool hasMoreWorkOrWasStopRequested()
Predicate for condition variable used communication with the worker thread.
Definition: ThreadedDispatcher.cpp:178
void doWork(const std::string &name, int priority)
The dispatcher thread entry point.
Definition: ThreadedDispatcher.cpp:182
virtual bool invokedFromDispatcherThread() final
Get dispatcher thread Id.
Definition: ThreadedDispatcher.cpp:83