libabigail
|
This represents a queue of tasks to be performed. More...
#include <abg-workers.h>
Classes | |
struct | task_done_notify |
This functor is to notify listeners that a given task scheduled for execution has been fully executed. More... | |
Public Types | |
typedef std::vector< task_sptr > | tasks_type |
A convenience typedef for a vector of task_sptr. More... | |
Public Member Functions | |
queue () | |
Default constructor of the queue type. More... | |
queue (unsigned number_of_workers) | |
Constructor of the queue type. More... | |
queue (unsigned number_of_workers, task_done_notify ¬ifier) | |
Constructor of the queue type. More... | |
~queue () | |
Destructor for the queue type. More... | |
tasks_type & | get_completed_tasks () const |
Getter of the vector of tasks that got performed. More... | |
size_t | get_size () const |
Getter of the size of the queue. This gives the number of task still present in the queue. More... | |
bool | schedule_task (const task_sptr &) |
Submit a task to the queue of tasks to be performed. More... | |
bool | schedule_tasks (const tasks_type &) |
Submit a vector of tasks to the queue of tasks to be performed. More... | |
void | wait_for_workers_to_complete () |
Suspends the current thread until all worker threads finish performing the tasks they are executing. More... | |
This represents a queue of tasks to be performed.
Tasks are performed by a number of worker threads.
When a task is inserted into a queue, the task is said to be "scheduled for execution".
This is because there are worker threads waiting for tasks to be added to the queue. When a task is added to the queue, a worker thread picks it up, executes it, notifies interested listeners when the task's execution is completed, and waits for another task to be added to the queue.
Of course, several worker threads can execute tasks concurrently.
Definition at line 67 of file abg-workers.h.
typedef std::vector<task_sptr> tasks_type |
A convenience typedef for a vector of task_sptr.
Definition at line 73 of file abg-workers.h.
queue | ( | ) |
Default constructor of the queue type.
By default the queue is created with a number of worker threaders which is equals to the number of simultaneous execution threads supported by the underlying processor.
Definition at line 267 of file abg-workers.cc.
queue | ( | unsigned | number_of_workers | ) |
Constructor of the queue type.
number_of_workers | the number of worker threads to have in the pool. |
Definition at line 275 of file abg-workers.cc.
queue | ( | unsigned | number_of_workers, |
task_done_notify & | notifier | ||
) |
Constructor of the queue type.
number_of_workers | the number of worker threads to have in the pool. |
the | notifier to invoke when a task is done doing its job. Users should create a type that inherit this task_done_notify class and overload its virtual task_done_notify::operator() operator function. Note that the code of that task_done_notify::operator() is assured to run in *sequence*, with respect to the code of other task_done_notify::operator() from other tasks. |
Definition at line 291 of file abg-workers.cc.
~queue | ( | ) |
Destructor for the queue type.
Definition at line 351 of file abg-workers.cc.
std::vector< task_sptr > & get_completed_tasks | ( | ) | const |
Getter of the vector of tasks that got performed.
Definition at line 347 of file abg-workers.cc.
size_t get_size | ( | ) | const |
Getter of the size of the queue. This gives the number of task still present in the queue.
Definition at line 301 of file abg-workers.cc.
bool schedule_task | ( | const task_sptr & | t | ) |
Submit a task to the queue of tasks to be performed.
This wakes up one thread from the pool which immediatly starts performing the task. When it's done with the task, it goes back to be suspended, waiting for a new task to be scheduled.
t | the task to schedule. Note that if the queue is empty or if the task is nil, the task is not scheduled. |
Definition at line 315 of file abg-workers.cc.
bool schedule_tasks | ( | const tasks_type & | tasks | ) |
Submit a vector of tasks to the queue of tasks to be performed.
This wakes up one or more threads from the pool which immediatly start performing the tasks. When the threads are done with the tasks, they goes back to be suspended, waiting for a new task to be scheduled.
tasks | the tasks to schedule. |
Definition at line 327 of file abg-workers.cc.
void wait_for_workers_to_complete | ( | ) |
Suspends the current thread until all worker threads finish performing the tasks they are executing.
If the worker threads were suspended waiting for a new task to perform, they are woken up and their execution ends.
The execution of the current thread is resumed when all the threads of the pool have finished their execution and are terminated.
Definition at line 340 of file abg-workers.cc.