CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
edm::SerialTaskQueue Class Reference

#include <SerialTaskQueue.h>

Classes

class  QueuedTask
 
class  TaskBase
 

Public Member Functions

bool isPaused () const
 Checks to see if the queue has been paused. More...
 
const SerialTaskQueueoperator= (const SerialTaskQueue &)=delete
 
bool pause ()
 Pauses processing of additional tasks from the queue. More...
 
template<typename T >
void push (tbb::task_group &, const T &iAction)
 asynchronously pushes functor iAction into queue More...
 
bool resume ()
 Resumes processing if the queue was paused. More...
 
 SerialTaskQueue ()
 
 SerialTaskQueue (const SerialTaskQueue &)=delete
 
 SerialTaskQueue (SerialTaskQueue &&iOther)
 
 ~SerialTaskQueue ()
 

Private Member Functions

TaskBasefinishedTask ()
 
TaskBasepickNextTask ()
 
TaskBasepushAndGetNextTask (TaskBase *)
 
void pushTask (TaskBase *)
 
void spawn (TaskBase &)
 

Private Attributes

std::atomic< unsigned long > m_pauseCount
 
std::atomic< bool > m_taskChosen
 
tbb::concurrent_queue< TaskBase * > m_tasks
 

Friends

class TaskBase
 

Detailed Description

Definition at line 67 of file SerialTaskQueue.h.

Constructor & Destructor Documentation

◆ SerialTaskQueue() [1/3]

edm::SerialTaskQueue::SerialTaskQueue ( )
inline

Definition at line 69 of file SerialTaskQueue.h.

69 : m_taskChosen(false), m_pauseCount{0} {}

◆ SerialTaskQueue() [2/3]

edm::SerialTaskQueue::SerialTaskQueue ( SerialTaskQueue &&  iOther)
inline

Definition at line 71 of file SerialTaskQueue.h.

72  : m_tasks(std::move(iOther.m_tasks)),
73  m_taskChosen(iOther.m_taskChosen.exchange(false)),
74  m_pauseCount(iOther.m_pauseCount.exchange(0)) {
75  assert(m_tasks.empty() and m_taskChosen == false);
76  }

References cms::cuda::assert(), m_taskChosen, and m_tasks.

◆ SerialTaskQueue() [3/3]

edm::SerialTaskQueue::SerialTaskQueue ( const SerialTaskQueue )
delete

◆ ~SerialTaskQueue()

SerialTaskQueue::~SerialTaskQueue ( )

Definition at line 27 of file SerialTaskQueue.cc.

27  {
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  tbb::task_group g;
33  g.run([&g, this]() {
34  tbb::task::suspend(
35  [&g, this](tbb::task::suspend_point tag) { push(g, [tag]() { tbb::task::resume(tag); }); }); //suspend
36  }); //group run
37  g.wait();
38  }
39 }

References g, isPaused(), m_taskChosen, m_tasks, or, push(), and GlobalPosition_Frontier_DevDB_cff::tag.

Member Function Documentation

◆ finishedTask()

SerialTaskQueue::TaskBase * SerialTaskQueue::finishedTask ( )
private

Definition at line 85 of file SerialTaskQueue.cc.

85  {
86  m_taskChosen.store(false);
87  return pickNextTask();
88 }

References m_taskChosen, and pickNextTask().

Referenced by spawn().

◆ isPaused()

bool edm::SerialTaskQueue::isPaused ( ) const
inline

Checks to see if the queue has been paused.

Returns
true if the queue is paused
See also
pause(), resume()

Definition at line 87 of file SerialTaskQueue.h.

87 { return m_pauseCount.load() != 0; }

References m_pauseCount.

Referenced by ~SerialTaskQueue().

◆ operator=()

const SerialTaskQueue& edm::SerialTaskQueue::operator= ( const SerialTaskQueue )
delete

◆ pause()

bool edm::SerialTaskQueue::pause ( )
inline

Pauses processing of additional tasks from the queue.

Any task already running will not be paused however once that running task finishes no further tasks will be started. Multiple calls to pause() are allowed, however each call to pause() must be balanced by a call to resume().

Returns
false if queue was already paused.
See also
resume(), isPaused()

Definition at line 99 of file SerialTaskQueue.h.

99 { return 1 == ++m_pauseCount; }

References m_pauseCount.

Referenced by edm::EventProcessor::beginLumiAsync(), and edm::LimitedTaskQueue::Resumer::Resumer().

◆ pickNextTask()

SerialTaskQueue::TaskBase * SerialTaskQueue::pickNextTask ( )
private

Definition at line 90 of file SerialTaskQueue.cc.

90  {
91  bool expect = false;
92  if LIKELY (0 == m_pauseCount and m_taskChosen.compare_exchange_strong(expect, true)) {
93  TaskBase* t = nullptr;
94  if LIKELY (m_tasks.try_pop(t)) {
95  return t;
96  }
97  //no task was actually pulled
98  m_taskChosen.store(false);
99 
100  //was a new entry added after we called 'try_pop' but before we did the clear?
101  expect = false;
102  if (not m_tasks.empty() and m_taskChosen.compare_exchange_strong(expect, true)) {
103  t = nullptr;
104  if (m_tasks.try_pop(t)) {
105  return t;
106  }
107  //no task was still pulled since a different thread beat us to it
108  m_taskChosen.store(false);
109  }
110  }
111  return nullptr;
112 }

References LIKELY, m_pauseCount, m_taskChosen, m_tasks, and submitPVValidationJobs::t.

Referenced by finishedTask(), pushAndGetNextTask(), and resume().

◆ push()

template<typename T >
void SerialTaskQueue::push ( tbb::task_group &  iGroup,
const T iAction 
)

asynchronously pushes functor iAction into queue

The function will return immediately and iAction will either process concurrently with the calling thread or wait until the protected resource becomes available or until a CPU becomes available.

Parameters
[in]iActionMust be a functor that takes no arguments and return no values.

Definition at line 167 of file SerialTaskQueue.h.

167  {
168  QueuedTask<T>* pTask{new QueuedTask<T>{iGroup, iAction}};
169  pushTask(pTask);
170  }

References pushTask().

Referenced by edm::EventProcessor::beginLumiAsync(), edm::eventsetup::ESSourceDataProxyBase::prefetchAsyncImpl(), and ~SerialTaskQueue().

◆ pushAndGetNextTask()

SerialTaskQueue::TaskBase * SerialTaskQueue::pushAndGetNextTask ( TaskBase iTask)
private

Definition at line 76 of file SerialTaskQueue.cc.

76  {
77  TaskBase* returnValue{nullptr};
78  if LIKELY (nullptr != iTask) {
79  m_tasks.push(iTask);
80  returnValue = pickNextTask();
81  }
82  return returnValue;
83 }

References LIKELY, m_tasks, and pickNextTask().

Referenced by pushTask().

◆ pushTask()

void SerialTaskQueue::pushTask ( TaskBase iTask)
private

Definition at line 69 of file SerialTaskQueue.cc.

69  {
70  auto t = pushAndGetNextTask(iTask);
71  if (nullptr != t) {
72  spawn(*t);
73  }
74 }

References pushAndGetNextTask(), spawn(), and submitPVValidationJobs::t.

Referenced by push().

◆ resume()

bool SerialTaskQueue::resume ( )

Resumes processing if the queue was paused.

Multiple calls to resume() are allowed if there were multiple calls to pause(). Only when we reach as many resume() calls as pause() calls will the queue restart.

Returns
true if the call really restarts the queue
See also
pause(), isPaused()

Definition at line 58 of file SerialTaskQueue.cc.

58  {
59  if (0 == --m_pauseCount) {
60  auto t = pickNextTask();
61  if (nullptr != t) {
62  spawn(*t);
63  }
64  return true;
65  }
66  return false;
67 }

References m_pauseCount, pickNextTask(), spawn(), and submitPVValidationJobs::t.

Referenced by edm::EventProcessor::globalEndLumiAsync(), edm::LimitedTaskQueue::Resumer::operator=(), and edm::Worker::RunModuleTask< T >::EnableQueueGuard::~EnableQueueGuard().

◆ spawn()

void SerialTaskQueue::spawn ( TaskBase iTask)
private

Definition at line 41 of file SerialTaskQueue.cc.

41  {
42  auto pTask = &iTask;
43  iTask.group()->run([pTask, this]() {
44  TaskBase* t = pTask;
45  auto g = pTask->group();
46  do {
47  t->execute();
48  delete t;
49  t = finishedTask();
50  if (t and t->group() != g) {
51  spawn(*t);
52  t = nullptr;
53  }
54  } while (t != nullptr);
55  });
56 }

References finishedTask(), g, edm::SerialTaskQueue::TaskBase::group(), and submitPVValidationJobs::t.

Referenced by pushTask(), and resume().

Friends And Related Function Documentation

◆ TaskBase

friend class TaskBase
friend

Definition at line 150 of file SerialTaskQueue.h.

Member Data Documentation

◆ m_pauseCount

std::atomic<unsigned long> edm::SerialTaskQueue::m_pauseCount
private

Definition at line 163 of file SerialTaskQueue.h.

Referenced by isPaused(), pause(), pickNextTask(), and resume().

◆ m_taskChosen

std::atomic<bool> edm::SerialTaskQueue::m_taskChosen
private

Definition at line 162 of file SerialTaskQueue.h.

Referenced by finishedTask(), pickNextTask(), SerialTaskQueue(), and ~SerialTaskQueue().

◆ m_tasks

tbb::concurrent_queue<TaskBase*> edm::SerialTaskQueue::m_tasks
private
edm::SerialTaskQueue::spawn
void spawn(TaskBase &)
Definition: SerialTaskQueue.cc:41
cms::cuda::assert
assert(be >=bs)
edm::SerialTaskQueue::push
void push(tbb::task_group &, const T &iAction)
asynchronously pushes functor iAction into queue
Definition: SerialTaskQueue.h:167
edm::TaskBase
Definition: TaskBase.h:31
edm::SerialTaskQueue::pushAndGetNextTask
TaskBase * pushAndGetNextTask(TaskBase *)
Definition: SerialTaskQueue.cc:76
edm::SerialTaskQueue::finishedTask
TaskBase * finishedTask()
Definition: SerialTaskQueue.cc:85
edm::SerialTaskQueue::pickNextTask
TaskBase * pickNextTask()
Definition: SerialTaskQueue.cc:90
edm::SerialTaskQueue::m_pauseCount
std::atomic< unsigned long > m_pauseCount
Definition: SerialTaskQueue.h:163
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::SerialTaskQueue::m_tasks
tbb::concurrent_queue< TaskBase * > m_tasks
Definition: SerialTaskQueue.h:161
eostools.move
def move(src, dest)
Definition: eostools.py:511
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
edm::SerialTaskQueue::m_taskChosen
std::atomic< bool > m_taskChosen
Definition: SerialTaskQueue.h:162
or
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
edm::SerialTaskQueue::pushTask
void pushTask(TaskBase *)
Definition: SerialTaskQueue.cc:69
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
g
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
edm::SerialTaskQueue::isPaused
bool isPaused() const
Checks to see if the queue has been paused.
Definition: SerialTaskQueue.h:87