#include <worker.h>
|
static worker * | get () |
| Provide access to the executing worker thread object in the current thread context. More...
|
|
static void | add_async_event (event e) |
| Add an event to the workers queue from a different thread context. More...
|
|
|
void | promote_leader () |
| Find a free worker and promote it to become the next leader. More...
|
|
void | mark_free () |
| Let the dispatcher know that this thread is free to become a leader and take on some work. More...
|
|
void | run () |
| Main method of the thread. More...
|
|
Definition at line 55 of file worker.h.
tasks::worker::worker |
( |
uint8_t |
id, |
|
|
std::unique_ptr< loop_t > & |
loop |
|
) |
| |
tasks::worker::~worker |
( |
| ) |
|
|
virtual |
static void tasks::worker::add_async_event |
( |
event |
e | ) |
|
|
inlinestatic |
Add an event to the workers queue from a different thread context.
Definition at line 141 of file worker.h.
void tasks::worker::add_event |
( |
event |
e | ) |
|
|
inline |
Add an event to the workers queue.
Definition at line 138 of file worker.h.
Put a functor into the async work queue of a worker and notify it.
Definition at line 107 of file worker.h.
uint64_t tasks::worker::events_count |
( |
| ) |
const |
|
inline |
Return the number of events the worker has handled until now.
Definition at line 158 of file worker.h.
bool tasks::worker::exec_in_worker_ctx |
( |
task_func_t |
f | ) |
|
|
inline |
Executes task_func_t directly if called in leader thread context or delegates it. Returns true when task_func_t has been executed. If some work needs to be executed in the context of a worker thread (eg to modify a watcher) this method needs to be used.
Definition at line 89 of file worker.h.
static worker* tasks::worker::get |
( |
| ) |
|
|
inlinestatic |
Provide access to the executing worker thread object in the current thread context.
Definition at line 64 of file worker.h.
std::string tasks::worker::get_string |
( |
| ) |
const |
|
inline |
void tasks::worker::handle_io_event |
( |
ev_io * |
watcher, |
|
|
int |
revents |
|
) |
| |
void tasks::worker::handle_timer_event |
( |
ev_timer * |
watcher | ) |
|
uint8_t tasks::worker::id |
( |
| ) |
const |
|
inline |
Return the worker id.
Definition at line 61 of file worker.h.
struct ev_loop* tasks::worker::loop_ptr |
( |
| ) |
const |
|
inline |
Return the event loop pointer for this worker.
Definition at line 73 of file worker.h.
void tasks::worker::mark_free |
( |
| ) |
|
|
inlineprivate |
Let the dispatcher know that this thread is free to become a leader and take on some work.
Definition at line 227 of file worker.h.
void tasks::worker::promote_leader |
( |
| ) |
|
|
inlineprivate |
Find a free worker and promote it to become the next leader.
Definition at line 214 of file worker.h.
void tasks::worker::run |
( |
| ) |
|
|
private |
Main method of the thread.
Definition at line 44 of file worker.cpp.
void tasks::worker::set_event_loop |
( |
std::unique_ptr< loop_t > & |
loop | ) |
|
|
inline |
Pass the event loop to the worker.
Definition at line 117 of file worker.h.
Same as exec_in_ctx(task_func_t f)
Definition at line 102 of file worker.h.
void tasks::worker::terminate |
( |
| ) |
|
|
inline |
Terminate the worker and wait for it to finish.
Definition at line 125 of file worker.h.
uint64_t tasks::worker::m_events_count = 0 |
|
private |
std::queue<event> tasks::worker::m_events_queue |
|
private |
uint8_t tasks::worker::m_id |
|
private |
A thread local pointer to the worker thread.
Definition at line 193 of file worker.h.
std::atomic<bool> tasks::worker::m_leader |
|
private |
std::unique_ptr<loop_t> tasks::worker::m_loop |
|
private |
ev_async tasks::worker::m_signal_watcher |
|
private |
Every worker has an async watcher to be able to call into the leader thread context.
Definition at line 209 of file worker.h.
std::atomic<bool> tasks::worker::m_term |
|
private |
std::unique_ptr<std::thread> tasks::worker::m_thread |
|
private |
std::condition_variable tasks::worker::m_work_cond |
|
private |
std::mutex tasks::worker::m_work_mutex |
|
private |
thread_local worker * tasks::worker::m_worker_ptr = nullptr |
|
staticprivate |
The documentation for this class was generated from the following files: