#include <Worker.hpp>
A representation of a worker thread in a scheduler. Each Worker
owns a thread and its own work-stealing queue. The workers main process will keep popping jobs off its own queue until there are none left, in which case it will start stealing jobs from other workers to help with the overall work-load of the owning scheduler. Once no jobs are queued, the worker will go to sleep until signalled by its scheduler - for instance when a new job is scheduled.
Public Types | |
enum | State { State::ready, State::running, State::waiting, State::terminated } |
Represents the running state of a Worker More... | |
Public Member Functions | |
Worker ()=default | |
Worker (const uint32_t id, std::vector< Worker > *workers, const uint32_t max_jobs, std::mutex *parent_mutex, std::condition_variable *parent_cv, detail::AtomicCounter *parent_counter) | |
~Worker () | |
Worker (const Worker &other)=delete | |
Worker & | operator= (const Worker &)=delete |
Worker (Worker &&other) noexcept | |
Worker & | operator= (Worker &&other) noexcept |
void | start () |
Starts the workers main procedure and forks a new thread to run jobs on. More... | |
void | terminate () |
Terminates the thread but doesn't join it to the parent thread. More... | |
void | join () |
Joins the worker, waiting until its completely terminated before destruction. More... | |
void | schedule_job (Job *job) |
Schedules a new job to the worker and notifies it to wake up. More... | |
bool | owns_this_thread () |
Checks if the current thread is owned by this worker, returns true if so. More... | |
State | state () |
Gets workers current running state. More... | |
uint32_t | id () |
Gets the workers id. More... | |
void | try_run_job () |
Attempts to pop or steal a job and execute it once. More... | |
|
strong |
Represents the running state of a Worker
Enumerator | |
---|---|
ready | |
running | |
waiting | |
terminated |
|
default |
|
inline |
|
inline |
|
delete |
|
inlinenoexcept |
|
inline |
Gets the workers id.
void jobrocket::Worker::join | ( | ) |
Joins the worker, waiting until its completely terminated before destruction.
|
inline |
Checks if the current thread is owned by this worker, returns true if so.
void jobrocket::Worker::schedule_job | ( | Job * | job | ) |
Schedules a new job to the worker and notifies it to wake up.
void jobrocket::Worker::start | ( | ) |
Starts the workers main procedure and forks a new thread to run jobs on.
|
inline |
Gets workers current running state.
void jobrocket::Worker::terminate | ( | ) |
Terminates the thread but doesn't join it to the parent thread.
void jobrocket::Worker::try_run_job | ( | ) |
Attempts to pop or steal a job and execute it once.