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 #include "oneapi/tbb/task.h"
16 
17 // user include files
19 
21 
22 using namespace edm;
23 
24 //
25 // member functions
26 //
28  //be certain all tasks have completed
29  bool isEmpty = m_tasks.empty();
30  bool isTaskChosen = m_taskChosen;
31  if ((not isEmpty and not isPaused()) or isTaskChosen) {
32  oneapi::tbb::task_group g;
33  g.run([&g, this]() {
34  oneapi::tbb::task::suspend([&g, this](oneapi::tbb::task::suspend_point tag) {
35  push(g, [tag]() { oneapi::tbb::task::resume(tag); });
36  }); //suspend
37  }); //group run
38  g.wait();
39  }
40 }
41 
43  auto pTask = &iTask;
44  iTask.group()->run([pTask, this]() {
45  TaskBase* t = pTask;
46  auto g = pTask->group();
47  do {
48  t->execute();
49  delete t;
50  t = finishedTask();
51  if (t and t->group() != g) {
52  spawn(*t);
53  t = nullptr;
54  }
55  } while (t != nullptr);
56  });
57 }
58 
60  if (0 == --m_pauseCount) {
61  auto t = pickNextTask();
62  if (nullptr != t) {
63  spawn(*t);
64  }
65  return true;
66  }
67  return false;
68 }
69 
71  auto t = pushAndGetNextTask(iTask);
72  if (nullptr != t) {
73  spawn(*t);
74  }
75 }
76 
78  TaskBase* returnValue{nullptr};
79  if LIKELY (nullptr != iTask) {
80  m_tasks.push(iTask);
81  returnValue = pickNextTask();
82  }
83  return returnValue;
84 }
85 
87  m_taskChosen.store(false);
88  return pickNextTask();
89 }
90 
92  bool expect = false;
93  if LIKELY (0 == m_pauseCount and m_taskChosen.compare_exchange_strong(expect, true)) {
94  TaskBase* t = nullptr;
95  if LIKELY (m_tasks.try_pop(t)) {
96  return t;
97  }
98  //no task was actually pulled
99  m_taskChosen.store(false);
100 
101  //was a new entry added after we called 'try_pop' but before we did the clear?
102  expect = false;
103  if (not m_tasks.empty() and m_taskChosen.compare_exchange_strong(expect, true)) {
104  t = nullptr;
105  if (m_tasks.try_pop(t)) {
106  return t;
107  }
108  //no task was still pulled since a different thread beat us to it
109  m_taskChosen.store(false);
110  }
111  }
112  return nullptr;
113 }
114 
115 //
116 // const member functions
117 //
118 
119 //
120 // static member functions
121 //
TaskBase * pushAndGetNextTask(TaskBase *)
std::atomic< unsigned long > m_pauseCount
void push(oneapi::tbb::task_group &, const T &iAction)
asynchronously pushes functor iAction into queue
#define LIKELY(x)
Definition: Likely.h:20
void pushTask(TaskBase *)
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 g
Definition: Activities.doc:4
bool resume()
Resumes processing if the queue was paused.
TaskBase * finishedTask()
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
oneapi::tbb::concurrent_queue< TaskBase * > m_tasks
void spawn(TaskBase &)
HLT enums.
oneapi::tbb::task_group * group()