Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AICommon::ThreadedDispatcher Class Reference

A dispatcher that does all the work on a single, separate thread started in constructor. More...

#include <ThreadedDispatcher.h>

Inheritance diagram for AICommon::ThreadedDispatcher:
Inheritance graph
[legend]
Collaboration diagram for AICommon::ThreadedDispatcher:
Collaboration graph
[legend]

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
 

Detailed Description

A dispatcher that does all the work on a single, separate thread started in constructor.

Constructor & Destructor Documentation

◆ ThreadedDispatcher()

AICommon::ThreadedDispatcher::ThreadedDispatcher ( int  priority,
const std::string &  name = std::string() 
)

Creates a dispatcher with supplied SCHED_RR priority value and a thread name

Member Function Documentation

◆ next()

std::function< void()> AICommon::ThreadedDispatcher::next ( )
inlineprivate

Returns next work item.

Note
This function assumes that there is work to be done and that the mutex is acquired.

◆ post()

void AICommon::ThreadedDispatcher::post ( std::function< void()>  work)
finalvirtual

Post an item of work to be executed on the thread owned by this dispatcher.

Implements AICommon::IDispatcher.

◆ sync()

void AICommon::ThreadedDispatcher::sync ( )
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.


The documentation for this class was generated from the following files: