| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

SerialTaskQueue.cpp
Go to the documentation of this file.
1 /*
2 * SerialTaskQueue.cpp
3 *
4 * @date 2012-10-21
5 * @author Marco Clemencic
6 */
7
8 #include "GaudiKernel/SerialTaskQueue.h"
9
10 namespace Gaudi
11 {
12
13 SerialTaskQueue::SerialTaskQueue() : m_count( 0 ) {}
14
15 SerialTaskQueue::~SerialTaskQueue() { wait(); }
16
17 SerialTaskQueue::WorkItem::~WorkItem() {}
18
19 void SerialTaskQueue::add( WorkItem* item )
20 {
21 m_queue.push( new SerialWorkItem( item, this ) );
22 if ( ++m_count == 1 ) i_startNextItem();
23 }
24
25 void SerialTaskQueue::noteCompletion()
26 {
27 if ( --m_count != 0 ) i_startNextItem();
28 }
29
30 void SerialTaskQueue::wait() const
31 {
32 // wait until the queue is empty and all the tasks are completed
33 while ( ( !m_queue.empty() ) || m_count ) {
34 }
35 }
36
37 void SerialTaskQueue::i_startNextItem()
38 {
39 SerialWorkItem* item = 0;
40 m_queue.try_pop( item );
41 tbb::task::enqueue( *new ( tbb::task::allocate_root() ) SerialWorkItemRunner( item ) );
42 }
43
44 } /* namespace Gaudi */
Gaudi::SerialTaskQueue::WorkItem::~WorkItem
virtual ~WorkItem()
Definition: SerialTaskQueue.cpp:17
Gaudi::SerialTaskQueue::i_startNextItem
void i_startNextItem()
Definition: SerialTaskQueue.cpp:37
Gaudi::SerialTaskQueue::WorkItem
Base class for the task to be executed by the serial queue.
Definition: SerialTaskQueue.h:38
Gaudi::SerialTaskQueue::m_queue
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Definition: SerialTaskQueue.h:107
Gaudi::SerialTaskQueue::SerialWorkItem
Wrapper for the WorkItem class for internal concurrency bookkeeping.
Definition: SerialTaskQueue.h:66
Gaudi::SerialTaskQueue::wait
void wait() const
Block until all the currently enqueued tasks are completed.
Definition: SerialTaskQueue.cpp:30
Gaudi::SerialTaskQueue::SerialTaskQueue
SerialTaskQueue()
Default constructor.
Definition: SerialTaskQueue.cpp:13
Gaudi::SerialTaskQueue::~SerialTaskQueue
virtual ~SerialTaskQueue()
Block until all the enqueued tasks are completed.
Definition: SerialTaskQueue.cpp:15
Gaudi::SerialTaskQueue::add
void add(WorkItem *item)
Enqueue a WorkItem for execution.
Definition: SerialTaskQueue.cpp:19
Gaudi::SerialTaskQueue::SerialWorkItemRunner
Helper class to wrap a SerialWorkItem in a tbb::task.
Definition: SerialTaskQueue.h:84
Gaudi::SerialTaskQueue::noteCompletion
void noteCompletion()
Method used by the tasks to trigger the execution of the next task in the queue.
Definition: SerialTaskQueue.cpp:25
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
SerialTaskQueue.h
Gaudi::SerialTaskQueue::m_count
std::atomic< int > m_count
Counter of the currently running tasks.
Definition: SerialTaskQueue.h:105