Dobby
3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
|
A dispatcher that does all the work on a single, separate thread started in constructor. More...
#include <ThreadedDispatcher.h>
Public Member Functions | |
virtual void | post (std::function< void()> work) final |
virtual void | sync () final |
Ensures that anything that was in the queue before the call has been executed before returning. More... | |
virtual bool | invokedFromDispatcherThread () final |
Get dispatcher thread Id. | |
void | flush () |
Perform any work remaining in the queue, then stop accepting new work. | |
void | stop () |
Cancels any work that is not already in progress, stop accepting new work. | |
ThreadedDispatcher (const std::string &name=std::string()) | |
ThreadedDispatcher (int priority, const std::string &name=std::string()) | |
Private Types | |
typedef ThreadedDispatcher | This |
Private Member Functions | |
bool | hasMoreWorkOrWasStopRequested () |
Predicate for condition variable used communication with the worker thread. | |
void | doWork (const std::string &name, int priority) |
The dispatcher thread entry point. | |
std::function< void()> | next () |
Returns next work item. More... | |
Private Attributes | |
std::mutex | m |
std::condition_variable | cv |
bool | running |
std::deque< std::function< void()> > | q |
std::thread | t |
A dispatcher that does all the work on a single, separate thread started in constructor.
AICommon::ThreadedDispatcher::ThreadedDispatcher | ( | int | priority, |
const std::string & | name = std::string() |
||
) |
Creates a dispatcher with supplied SCHED_RR priority value and a thread name
|
inlineprivate |
Returns next work item.
|
finalvirtual |
Post an item of work to be executed on the thread owned by this dispatcher.
Implements AICommon::IDispatcher.
|
finalvirtual |
Ensures that anything that was in the queue before the call has been executed before returning.
Ensures that any items in the dispatch queue before this call are processed before the function returns.
The function blocks until everything in the queue prior to the call is processed.
It works by putting a dummy work item on the queue which takes a reference to a local conditional variable, we then wait on the conditional triggering.
Implements AICommon::IDispatcher.