| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::SerialTaskQueue Class Reference

Class for a generic serial queue of tasks (modeled on the Intel Threading Building Blocks Design Pattern "Local Serializer"). More...

`#include <GaudiKernel/SerialTaskQueue.h>`

Collaboration diagram for Gaudi::SerialTaskQueue:
[legend]

## Classes
class | SerialWorkItem
| Wrapper for the WorkItem class for internal concurrency bookkeeping. More...
class | SerialWorkItemRunner
| Helper class to wrap a SerialWorkItem in a tbb::task. More...
class | WorkItem
| Base class for the task to be executed by the serial queue. More...

## Public Member Functions
| SerialTaskQueue ()
| Default constructor. More...
virtual | ~SerialTaskQueue ()
| Block until all the enqueued tasks are completed. More...
void | add (WorkItem *item)
| Enqueue a WorkItem for execution. More...
void | noteCompletion ()
| Method used by the tasks to trigger the execution of the next task in the queue. More...
void | wait () const
| Block until all the currently enqueued tasks are completed. More...

## Private Member Functions
void | i_startNextItem ()

## Private Attributes
std::atomic< int > | m_count
| Counter of the currently running tasks. More...
tbb::concurrent_queue< SerialWorkItem * > | m_queue
| Queue of the tasks to be executed. More...

## Detailed Description

Class for a generic serial queue of tasks (modeled on the Intel Threading Building Blocks Design Pattern "Local Serializer").

Users of SerialTaskQueue must define the tasks to be executed specializing the class SerialTaskQueue::WorkItem, implementing the method WorkItem::run().

Tasks are enqueued via the method SerialTaskQueue::add(WorkItem*).

When the instance goes out of scope (or is destructed), the thread blocks until all the enqueued tasks are completed.

Author
  Marco Clemencic

Definition at line 32 of file SerialTaskQueue.h.

## Constructor & Destructor Documentation

## ◆ SerialTaskQueue()

Gaudi::SerialTaskQueue::SerialTaskQueue | ( |  | ) |

Default constructor.

Definition at line 12 of file SerialTaskQueue.cpp.

12 : m_count( 0 ) {}
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

## ◆ ~SerialTaskQueue()

Gaudi::SerialTaskQueue::~SerialTaskQueue | ( |  | ) |
| virtual

Block until all the enqueued tasks are completed.

Definition at line 14 of file SerialTaskQueue.cpp.

14 { wait(); }
Gaudi::SerialTaskQueue::wait
void wait() const
Block until all the currently enqueued tasks are completed.
Definition: SerialTaskQueue.cpp:27

## Member Function Documentation

## ◆ add()

void Gaudi::SerialTaskQueue::add | ( | WorkItem * | item | ) |

Enqueue a WorkItem for execution.

Definition at line 18 of file SerialTaskQueue.cpp.

18 {
19 m_queue.push( new SerialWorkItem( item, this ) );
20 if ( ++m_count == 1 ) i_startNextItem();
21 }
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:32
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:101
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

## ◆ i_startNextItem()

void Gaudi::SerialTaskQueue::i_startNextItem | ( |  | ) |
| private

Definition at line 32 of file SerialTaskQueue.cpp.

32 {
33 SerialWorkItem* item = 0;
34 m_queue.try_pop( item );
35 tbb::task::enqueue( *new ( tbb::task::allocate_root() ) SerialWorkItemRunner( item ) );
36 }
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:101

## ◆ noteCompletion()

void Gaudi::SerialTaskQueue::noteCompletion | ( |  | ) |

Method used by the tasks to trigger the execution of the next task in the queue.

Definition at line 23 of file SerialTaskQueue.cpp.

23 {
24 if ( --m_count != 0 ) i_startNextItem();
25 }
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:32
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

## ◆ wait()

void Gaudi::SerialTaskQueue::wait | ( |  | ) | const

Block until all the currently enqueued tasks are completed.

Note
  while a thread is waiting for the tasks to be completes, another may still enqueue other tasks.

Definition at line 27 of file SerialTaskQueue.cpp.

27 {
28 // wait until the queue is empty and all the tasks are completed
29 while ( ( !m_queue.empty() ) || m_count ) {}
30 }
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:101
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

## Member Data Documentation

## ◆ m_count

std::atomic<int> Gaudi::SerialTaskQueue::m_count
| private

Counter of the currently running tasks.

Definition at line 99 of file SerialTaskQueue.h.

## ◆ m_queue

tbb::concurrent_queue<SerialWorkItem*> Gaudi::SerialTaskQueue::m_queue
| private

Queue of the tasks to be executed.

Definition at line 101 of file SerialTaskQueue.h.

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

- GaudiKernel/GaudiKernel/SerialTaskQueue.h
- GaudiKernel/src/Lib/SerialTaskQueue.cpp