CMS 3D CMS Logo

SerialTaskQueue.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Concurrency
4 // Class : SerialTaskQueue
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Feb 21 11:31:52 CST 2013
11 // $Id$
12 //
13 
14 // system include files
15 
16 // user include files
18 
20 
21 using namespace edm;
22 
23 //
24 // member functions
25 //
27  //be certain all tasks have completed
28  bool isEmpty = m_tasks.empty();
29  bool isTaskChosen = m_taskChosen;
30  if ((not isEmpty and not isPaused()) or isTaskChosen) {
31  pushAndWait([]() { return; });
32  }
33 }
34 
36  if (0 == --m_pauseCount) {
38  if (nullptr != t) {
39  tbb::task::spawn(*t);
40  }
41  return true;
42  }
43  return false;
44 }
45 
47  tbb::task* t = pushAndGetNextTask(iTask);
48  if (nullptr != t) {
49  tbb::task::spawn(*t);
50  }
51 }
52 
54  tbb::task* returnValue{nullptr};
55  if
56  LIKELY(nullptr != iTask) {
57  m_tasks.push(iTask);
58  returnValue = pickNextTask();
59  }
60  return returnValue;
61 }
62 
64  m_taskChosen.store(false);
65  return pickNextTask();
66 }
67 
69  bool expect = false;
70  if
71  LIKELY(0 == m_pauseCount and m_taskChosen.compare_exchange_strong(expect, true)) {
72  TaskBase* t = nullptr;
73  if
74  LIKELY(m_tasks.try_pop(t)) { return t; }
75  //no task was actually pulled
76  m_taskChosen.store(false);
77 
78  //was a new entry added after we called 'try_pop' but before we did the clear?
79  expect = false;
80  if (not m_tasks.empty() and m_taskChosen.compare_exchange_strong(expect, true)) {
81  TaskBase* t = nullptr;
82  if (m_tasks.try_pop(t)) {
83  return t;
84  }
85  //no task was still pulled since a different thread beat us to it
86  m_taskChosen.store(false);
87  }
88  }
89  return nullptr;
90 }
91 
92 void SerialTaskQueue::pushAndWait(tbb::empty_task* iWait, TaskBase* iTask) {
93  auto nextTask = pushAndGetNextTask(iTask);
94  if
95  LIKELY(nullptr != nextTask) {
96  if
97  LIKELY(nextTask == iTask) {
98  //spawn and wait for all requires the task to have its parent set
99  iWait->spawn_and_wait_for_all(*nextTask);
100  }
101  else {
102  tbb::task::spawn(*nextTask);
103  iWait->wait_for_all();
104  }
105  }
106  else {
107  //a task must already be running in this queue
108  iWait->wait_for_all();
109  }
110  tbb::task::destroy(*iWait);
111 }
112 
113 //
114 // const member functions
115 //
116 
117 //
118 // static member functions
119 //
tbb::task * finishedTask()
void pushAndWait(const T &iAction)
synchronously pushes functor iAction into queue
std::atomic< unsigned long > m_pauseCount
def destroy(e)
Definition: pyrootRender.py:15
tbb::task * pushAndGetNextTask(TaskBase *)
#define LIKELY(x)
Definition: Likely.h:20
void pushTask(TaskBase *)
bool resume()
Resumes processing if the queue was paused.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool isPaused() const
Checks to see if the queue has been paused.
TaskBase * pickNextTask()
std::atomic< bool > m_taskChosen
HLT enums.
tbb::concurrent_queue< TaskBase * > m_tasks