libabigail
Classes | Public Types | Public Member Functions | List of all members
queue Class Reference

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 &notifier)
 Constructor of the queue type. More...
 
 ~queue ()
 Destructor for the queue type. More...
 
tasks_typeget_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...
 

Detailed Description

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.

Member Typedef Documentation

◆ tasks_type

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.

Constructor & Destructor Documentation

◆ queue() [1/3]

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() [2/3]

queue ( unsigned  number_of_workers)

Constructor of the queue type.

Parameters
number_of_workersthe number of worker threads to have in the pool.

Definition at line 275 of file abg-workers.cc.

◆ queue() [3/3]

queue ( unsigned  number_of_workers,
task_done_notify notifier 
)

Constructor of the queue type.

Parameters
number_of_workersthe number of worker threads to have in the pool.
thenotifier 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()

~queue ( )

Destructor for the queue type.

Definition at line 351 of file abg-workers.cc.

Member Function Documentation

◆ get_completed_tasks()

std::vector< task_sptr > & get_completed_tasks ( ) const

Getter of the vector of tasks that got performed.

Returns
the vector of tasks that got performed.

Definition at line 347 of file abg-workers.cc.

◆ get_size()

size_t get_size ( ) const

Getter of the size of the queue. This gives the number of task still present in the queue.

Returns
the number of task still present in the queue.

Definition at line 301 of file abg-workers.cc.

◆ schedule_task()

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.

Parameters
tthe task to schedule. Note that if the queue is empty or if the task is nil, the task is not scheduled.
Returns
true iff the task was successfully scheduled.

Definition at line 315 of file abg-workers.cc.

◆ schedule_tasks()

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.

Parameters
tasksthe tasks to schedule.

Definition at line 327 of file abg-workers.cc.

◆ wait_for_workers_to_complete()

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.


The documentation for this class was generated from the following files: