CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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

Definition at line 41 of file LimitedTaskQueue.h.

41 : m_queues{iLimit} {}
std::vector< SerialTaskQueue > m_queues
edm::LimitedTaskQueue::LimitedTaskQueue ( const LimitedTaskQueue )
delete

Member Function Documentation

unsigned int edm::LimitedTaskQueue::concurrencyLimit ( ) const
inline
const LimitedTaskQueue& edm::LimitedTaskQueue::operator= ( const LimitedTaskQueue )
delete
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
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

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

Definition at line 111 of file LimitedTaskQueue.h.

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