| The Gaudi Framework v27r1

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

## Constructor & Destructor Documentation

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

Default constructor.

Definition at line 12 of file SerialTaskQueue.cpp.

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

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

Block until all the enqueued tasks are completed.

Definition at line 15 of file SerialTaskQueue.cpp.

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

## Member Function Documentation

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

Enqueue a WorkItem for execution.

Definition at line 22 of file SerialTaskQueue.cpp.

22 {
23 m_queue.push(new SerialWorkItem(item, this));
24 if (++m_count == 1)
25 i_startNextItem();
26 }
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:38
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:101
ana.item
tuple item
print s1,s2
Definition: ana.py:146
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

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

Definition at line 38 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:101
ana.item
tuple item
print s1,s2
Definition: ana.py:146

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

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

Definition at line 28 of file SerialTaskQueue.cpp.

28 {
29 if (--m_count!=0)
30 i_startNextItem();
31 }
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:38
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:99

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

33 {
34 // wait until the queue is empty and all the tasks are completed
35 while((!m_queue.empty()) || m_count) {}
36 }
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

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

Counter of the currently running tasks.

Definition at line 99 of file SerialTaskQueue.h.

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