| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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 33 of file SerialTaskQueue.h.

## Constructor & Destructor Documentation

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

Default constructor.

Definition at line 13 of file SerialTaskQueue.cpp.

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

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

Block until all the enqueued tasks are completed.

Definition at line 15 of file SerialTaskQueue.cpp.

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

## Member Function Documentation

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

Enqueue a WorkItem for execution.

Definition at line 19 of file SerialTaskQueue.cpp.

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

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

Definition at line 37 of file SerialTaskQueue.cpp.

38 {
39 SerialWorkItem* item = 0;
40 m_queue.try_pop( item );
41 tbb::task::enqueue( *new ( tbb::task::allocate_root() ) SerialWorkItemRunner( item ) );
42 }
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:107

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

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

Definition at line 25 of file SerialTaskQueue.cpp.

26 {
27 if ( --m_count != 0 ) i_startNextItem();
28 }
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:37
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:105

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 30 of file SerialTaskQueue.cpp.

31 {
32 // wait until the queue is empty and all the tasks are completed
33 while ( ( !m_queue.empty() ) || m_count ) {
34 }
35 }
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:107
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:105

## Member Data Documentation

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

Counter of the currently running tasks.

Definition at line 105 of file SerialTaskQueue.h.

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

Queue of the tasks to be executed.

Definition at line 107 of file SerialTaskQueue.h.

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

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