8 #ifndef _TASKS_DISPATCHER_H_
9 #define _TASKS_DISPATCHER_H_
13 #include <condition_variable>
49 m_instance = std::make_shared<dispatcher>(num_workers);
67 terr(
"ERROR: dispatcher::init_run_mode must be called before anything else!" << std::endl);
75 static std::shared_ptr<dispatcher>
instance() {
78 m_instance = std::make_shared<dispatcher>(sysconf(_SC_NPROCESSORS_ONLN));
131 [[deprecated]]
void run(
int num, ...);
134 void run(std::vector<tasks::task*>& tasks);
182 #endif // _TASKS_DISPATCHER_H_
static void init_workers(uint8_t num_workers)
std::mutex m_finish_mutex
static std::shared_ptr< dispatcher > instance()
The base class for any task.
void remove_exec_task(exec_task *task)
void add_task(task *task)
void run(int num,...)
This method starts the system and blocks until terminate() gets called.
std::list< std::shared_ptr< executor > > m_executors
All executor threads.
tools::bitset m_workers_busy
State of the workers used for maintaining the leader/followers.
std::shared_ptr< executor > free_executor()
Find a free executor. If non is found a new executor gets created.
std::condition_variable m_finish_cond
Condition variable/mutex used to wait for finishing up.
void remove_task(task *task)
Remove a task from the system.
tools::bitset::int_type m_last_worker_id
std::function< void(int)> signal_func_t
static std::shared_ptr< dispatcher > m_instance
void print_worker_stats() const
std::atomic< uint8_t > m_rr_worker_id
void add_event_task(event_task *task)
Add an event task to the system.
std::atomic< bool > m_term
std::mutex m_executor_mutex
static void init_run_mode(mode m)
void terminate()
Terminate the workers and die.
std::vector< std::shared_ptr< worker > > m_workers
All worker threads.
void add_exec_task(exec_task *task)
Add an exec task to the system.
worker * get_worker_by_task(event_task *task)
void add_free_worker(uint8_t id)
When a worker finishes his work he returns to the free worker queue.
dispatcher(uint8_t num_workers)
void start()
Start the event loop. Do not block.
void join()
Wait for the dispatcher to finish.
static void add_signal_handler(int sig, signal_func_t func)
void remove_event_task(event_task *task)
std::shared_ptr< worker > free_worker()
Get a free worker to promote it to the leader.