#include <dispatcher.h>
Definition at line 36 of file dispatcher.h.
Enumerator |
---|
SINGLE_LOOP |
|
MULTI_LOOP |
|
Definition at line 40 of file dispatcher.h.
tasks::dispatcher::dispatcher |
( |
uint8_t |
num_workers | ) |
|
void tasks::dispatcher::add_event_task |
( |
event_task * |
task | ) |
|
void tasks::dispatcher::add_exec_task |
( |
exec_task * |
task | ) |
|
void tasks::dispatcher::add_free_worker |
( |
uint8_t |
id | ) |
|
When a worker finishes his work he returns to the free worker queue.
Definition at line 146 of file dispatcher.cpp.
void tasks::dispatcher::add_signal_handler |
( |
int |
sig, |
|
|
signal_func_t |
func |
|
) |
| |
|
static |
void tasks::dispatcher::add_task |
( |
task * |
task | ) |
|
Add a task to the system. This method will find out if the task is an event or exec task and handles it accordingly.
Definition at line 177 of file dispatcher.cpp.
static void tasks::dispatcher::destroy |
( |
| ) |
|
|
inlinestatic |
std::shared_ptr< executor > tasks::dispatcher::free_executor |
( |
| ) |
|
Find a free executor. If non is found a new executor gets created.
Definition at line 122 of file dispatcher.cpp.
std::shared_ptr< worker > tasks::dispatcher::free_worker |
( |
| ) |
|
Get a free worker to promote it to the leader.
Definition at line 109 of file dispatcher.cpp.
Return the worker assigned to a task. If no worker is assigned to the given task, a worker is picked depending on the run mode.
Definition at line 151 of file dispatcher.cpp.
static void tasks::dispatcher::init_run_mode |
( |
mode |
m | ) |
|
|
inlinestatic |
Set the run mode. The default is to run a leader/followers system (MODE_SINGLE_LOOP) in which only one event loop exists that is passed from worker to worker. An alternative is to run an event loop in each worker (MODE_MULTI_LOOP). This can improve the responsiveness and throughput in some situations.
Note: This method has to be called before creating the dispatcher singleton. It will fail when called later.
Available Modes: SINGLE_LOOP (Default) MULTI_LOOP
Definition at line 65 of file dispatcher.h.
static void tasks::dispatcher::init_workers |
( |
uint8_t |
num_workers | ) |
|
|
inlinestatic |
Use this method to override the number of worker threads. The default is the number of CPU's. This method needs to be called before the first call to instance().
Definition at line 47 of file dispatcher.h.
static std::shared_ptr<dispatcher> tasks::dispatcher::instance |
( |
| ) |
|
|
inlinestatic |
void tasks::dispatcher::join |
( |
| ) |
|
Wait for the dispatcher to finish.
Definition at line 98 of file dispatcher.cpp.
worker* tasks::dispatcher::last_worker |
( |
| ) |
|
|
inline |
Returns the last promoted worker from the workers vector. This can be useful to add tasks in situations where a worker handle is not available.
Definition at line 109 of file dispatcher.h.
void tasks::dispatcher::print_worker_stats |
( |
| ) |
const |
void tasks::dispatcher::remove_event_task |
( |
event_task * |
task | ) |
|
void tasks::dispatcher::remove_exec_task |
( |
exec_task * |
task | ) |
|
void tasks::dispatcher::remove_task |
( |
task * |
task | ) |
|
void tasks::dispatcher::run |
( |
int |
num, |
|
|
|
... |
|
) |
| |
void tasks::dispatcher::run |
( |
std::vector< tasks::task * > & |
tasks | ) |
|
static mode tasks::dispatcher::run_mode |
( |
| ) |
|
|
inlinestatic |
void tasks::dispatcher::start |
( |
| ) |
|
Start the event loop. Do not block.
Definition at line 63 of file dispatcher.cpp.
void tasks::dispatcher::terminate |
( |
| ) |
|
|
inline |
Terminate the workers and die.
Definition at line 143 of file dispatcher.h.
std::mutex tasks::dispatcher::m_executor_mutex |
|
private |
std::list<std::shared_ptr<executor> > tasks::dispatcher::m_executors |
|
private |
std::condition_variable tasks::dispatcher::m_finish_cond |
|
private |
Condition variable/mutex used to wait for finishing up.
Definition at line 174 of file dispatcher.h.
std::mutex tasks::dispatcher::m_finish_mutex |
|
private |
std::shared_ptr< dispatcher > tasks::dispatcher::m_instance = nullptr |
|
staticprivate |
uint8_t tasks::dispatcher::m_num_workers = 0 |
|
private |
std::atomic<uint8_t> tasks::dispatcher::m_rr_worker_id |
|
private |
A round robin counter to add tasks to the system. In case each worker runs it's own event loop this is useful to distribute tasks across the workers.
Definition at line 171 of file dispatcher.h.
bool tasks::dispatcher::m_started = false |
|
private |
std::atomic<bool> tasks::dispatcher::m_term |
|
private |
std::vector<std::shared_ptr<worker> > tasks::dispatcher::m_workers |
|
private |
State of the workers used for maintaining the leader/followers.
Definition at line 165 of file dispatcher.h.
The documentation for this class was generated from the following files: