The Gaudi Framework  v33r0 (d5ea422b)
SerialTaskQueue.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 /*
12  * SerialTaskQueue.cpp
13  *
14  * @date 2012-10-21
15  * @author Marco Clemencic
16  */
17 
19 
20 namespace Gaudi {
21 
23 
25 
27 
29  m_queue.push( new SerialWorkItem( item, this ) );
30  if ( ++m_count == 1 ) i_startNextItem();
31  }
32 
34  if ( --m_count != 0 ) i_startNextItem();
35  }
36 
37  void SerialTaskQueue::wait() const {
38  // wait until the queue is empty and all the tasks are completed
39  while ( ( !m_queue.empty() ) || m_count ) {}
40  }
41 
43  SerialWorkItem* item = 0;
44  m_queue.try_pop( item );
45  tbb::task::enqueue( *new ( tbb::task::allocate_root() ) SerialWorkItemRunner( item ) );
46  }
47 
48 } /* namespace Gaudi */
Base class for the task to be executed by the serial queue.
tbb::concurrent_queue< SerialWorkItem * > m_queue
Queue of the tasks to be executed.
Wrapper for the WorkItem class for internal concurrency bookkeeping.
SerialTaskQueue()
Default constructor.
void wait() const
Block until all the currently enqueued tasks are completed.
virtual ~SerialTaskQueue()
Block until all the enqueued tasks are completed.
void add(WorkItem *item)
Enqueue a WorkItem for execution.
Helper class to wrap a SerialWorkItem in a tbb::task.
void noteCompletion()
Method used by the tasks to trigger the execution of the next task in the queue.
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
std::atomic< int > m_count
Counter of the currently running tasks.