CMS 3D CMS Logo

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

#include <LimitedTaskQueue.h>

Classes

class  Resumer
 

Public Member Functions

unsigned int concurrencyLimit () const
 
 LimitedTaskQueue (const LimitedTaskQueue &)=delete
 
 LimitedTaskQueue (unsigned int iLimit)
 
const LimitedTaskQueueoperator= (const LimitedTaskQueue &)=delete
 
template<typename T >
void push (tbb::task_group &iGroup, T &&iAction)
 asynchronously pushes functor iAction into queue More...
 
template<typename T >
void pushAndPause (tbb::task_group &iGroup, T &&iAction)
 asynchronously pushes functor iAction into queue then pause the queue and run iAction More...
 

Private Attributes

std::vector< SerialTaskQueuem_queues
 

Detailed Description

Definition at line 39 of file LimitedTaskQueue.h.

Constructor & Destructor Documentation

◆ LimitedTaskQueue() [1/2]

edm::LimitedTaskQueue::LimitedTaskQueue ( unsigned int  iLimit)
inline

Definition at line 41 of file LimitedTaskQueue.h.

41 : m_queues{iLimit} {}

◆ LimitedTaskQueue() [2/2]

edm::LimitedTaskQueue::LimitedTaskQueue ( const LimitedTaskQueue )
delete

Member Function Documentation

◆ concurrencyLimit()

unsigned int edm::LimitedTaskQueue::concurrencyLimit ( ) const
inline

◆ operator=()

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

◆ push()

template<typename T >
void LimitedTaskQueue::push ( tbb::task_group &  iGroup,
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 115 of file LimitedTaskQueue.h.

115  {
116  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
117  for (auto& q : m_queues) {
118  q.push(iGroup, [set_to_run, iAction]() mutable {
119  bool expected = false;
120  if (set_to_run->compare_exchange_strong(expected, true)) {
121  iAction();
122  }
123  });
124  }
125  }

References m_queues, and submitPVResolutionJobs::q.

Referenced by edm::Worker::TaskQueueAdaptor::push().

◆ pushAndPause()

template<typename T >
void LimitedTaskQueue::pushAndPause ( tbb::task_group &  iGroup,
T &&  iAction 
)

asynchronously pushes functor iAction into queue then pause the queue and run iAction

iAction must take as argument a copy of a LimitedTaskQueue::Resumer. To resume the queue let the last copy of the Resumer go out of scope, or call Resumer::resume(). Using this function will decrease the allowed concurrency limit by 1.

Definition at line 128 of file LimitedTaskQueue.h.

128  {
129  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
130  for (auto& q : m_queues) {
131  q.push(iGroup, [&q, set_to_run, iAction]() mutable {
132  bool expected = false;
133  if (set_to_run->compare_exchange_strong(expected, true)) {
134  q.pause();
135  iAction(Resumer(&q));
136  }
137  });
138  }
139  }

References m_queues, and submitPVResolutionJobs::q.

Referenced by edm::eventsetup::EventSetupRecordIOVQueue::startNewIOVAsync().

Member Data Documentation

◆ m_queues

std::vector<SerialTaskQueue> edm::LimitedTaskQueue::m_queues
private

Definition at line 111 of file LimitedTaskQueue.h.

Referenced by concurrencyLimit(), push(), and pushAndPause().

edm::LimitedTaskQueue::m_queues
std::vector< SerialTaskQueue > m_queues
Definition: LimitedTaskQueue.h:111
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84