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 (unsigned int iLimit)
 
 LimitedTaskQueue (const LimitedTaskQueue &)=delete
 
const LimitedTaskQueueoperator= (const LimitedTaskQueue &)=delete
 
template<typename T >
void push (oneapi::tbb::task_group &iGroup, T &&iAction)
 asynchronously pushes functor iAction into queue More...
 
template<typename T >
void pushAndPause (oneapi::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} {}
std::vector< SerialTaskQueue > m_queues

◆ 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 ( oneapi::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.

References m_queues, and submitPVResolutionJobs::q.

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

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  }
std::vector< SerialTaskQueue > m_queues

◆ pushAndPause()

template<typename T >
void LimitedTaskQueue::pushAndPause ( oneapi::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.

References m_queues, and submitPVResolutionJobs::q.

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

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  }
std::vector< SerialTaskQueue > m_queues

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().