22#include "abg-internal.h"
24ABG_BEGIN_EXPORT_DECLARATIONS
28ABG_END_EXPORT_DECLARATIONS
76{
return sysconf(_SC_NPROCESSORS_ONLN);}
91 wait_to_execute_a_task(queue::priv*);
105 bool bring_workers_down;
110 pthread_mutex_t tasks_todo_mutex;
115 pthread_cond_t tasks_todo_cond;
118 pthread_mutex_t tasks_done_mutex;
121 pthread_cond_t tasks_done_cond;
123 std::queue<task_sptr> tasks_todo;
125 std::vector<task_sptr> tasks_done;
131 static task_done_notify default_notify;
135 task_done_notify& notify;
137 std::vector<worker> workers;
148 task_done_notify& n = default_notify)
149 : bring_workers_down(),
150 num_workers(nb_workers),
163 for (
unsigned i = 0; i < num_workers; ++i)
168 (
void*(*)(
void*))&worker::wait_to_execute_a_task,
170 workers.push_back(w);
188 if (workers.empty() || !t)
191 pthread_mutex_lock(&tasks_todo_mutex);
193 pthread_mutex_unlock(&tasks_todo_mutex);
194 pthread_cond_signal(&tasks_todo_cond);
209 for (tasks_type::const_iterator t = tasks.begin(); t != tasks.end(); ++t)
229 do_bring_workers_down()
235 pthread_mutex_lock(&tasks_todo_mutex);
236 while (!tasks_todo.empty())
237 pthread_cond_wait(&tasks_done_cond, &tasks_todo_mutex);
239 bring_workers_down =
true;
240 pthread_mutex_unlock(&tasks_todo_mutex);
244 ABG_ASSERT(pthread_cond_broadcast(&tasks_todo_cond) == 0);
246 for (std::vector<worker>::const_iterator i = workers.begin();
255 {do_bring_workers_down();}
260queue::task_done_notify queue::priv::default_notify;
276 : p_(new priv(number_of_workers))
293 : p_(new priv(number_of_workers, notifier))
302{
return p_->tasks_todo.size();}
316{
return p_->schedule_task(t);}
328{
return p_->schedule_tasks(tasks);}
341{p_->do_bring_workers_down();}
346std::vector<task_sptr>&
348{
return p_->tasks_done;}
376worker::wait_to_execute_a_task(queue::priv* p)
380 pthread_mutex_lock(&p->tasks_todo_mutex);
383 while (p->tasks_todo.empty() && !p->bring_workers_down)
384 pthread_cond_wait(&p->tasks_todo_cond, &p->tasks_todo_mutex);
389 if (!p->tasks_todo.empty())
391 t = p->tasks_todo.front();
394 pthread_mutex_unlock(&p->tasks_todo_mutex);
410 pthread_mutex_lock(&p->tasks_done_mutex);
411 p->tasks_done.push_back(t);
413 pthread_mutex_unlock(&p->tasks_done_mutex);
414 pthread_cond_signal(&p->tasks_done_cond);
418 bool drop_out =
false;
419 pthread_mutex_lock(&p->tasks_todo_mutex);
420 drop_out = p->bring_workers_down;
421 pthread_mutex_unlock(&p->tasks_todo_mutex);
#define ABG_ASSERT(cond)
This is a wrapper around the 'assert' glibc call. It allows for its argument to have side effects,...
This file declares an interface for the worker threads (or thread pool) design pattern....
tasks_type & get_completed_tasks() const
Getter of the vector of tasks that got performed.
~queue()
Destructor for the queue type.
void wait_for_workers_to_complete()
Suspends the current thread until all worker threads finish performing the tasks they are executing.
std::vector< task_sptr > tasks_type
A convenience typedef for a vector of task_sptr.
size_t get_size() const
Getter of the size of the queue. This gives the number of task still present in the queue.
bool schedule_tasks(const tasks_type &)
Submit a vector of tasks to the queue of tasks to be performed.
queue()
Default constructor of the queue type.
bool schedule_task(const task_sptr &)
Submit a task to the queue of tasks to be performed.
size_t get_number_of_threads()
Toplevel namespace for libabigail.
This functor is to notify listeners that a given task scheduled for execution has been fully executed...
virtual void operator()(const task_sptr &task_done)
The default function invocation operator of the queue type.