CMS 3D CMS Logo

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

#include <LimitedTaskQueue.h>

Public Member Functions

unsigned int concurrencyLimit () const
 
 LimitedTaskQueue (unsigned int iLimit)
 
template<typename T >
void push (const T &iAction)
 asynchronously pushes functor iAction into queue More...
 
template<typename T >
void pushAndWait (const T &iAction)
 synchronously pushes functor iAction into queue More...
 

Private Member Functions

 LimitedTaskQueue (const LimitedTaskQueue &)=delete
 
const LimitedTaskQueueoperator= (const LimitedTaskQueue &)=delete
 

Private Attributes

std::vector< SerialTaskQueuem_queues
 

Detailed Description

Definition at line 38 of file LimitedTaskQueue.h.

Constructor & Destructor Documentation

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

Definition at line 41 of file LimitedTaskQueue.h.

References push(), and pushAndWait().

Referenced by concurrencyLimit().

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

Member Function Documentation

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

Definition at line 69 of file LimitedTaskQueue.h.

References LimitedTaskQueue(), m_queues, and operator=().

69 { return m_queues.size(); }
std::vector< SerialTaskQueue > m_queues
const LimitedTaskQueue& edm::LimitedTaskQueue::operator= ( const LimitedTaskQueue )
privatedelete

Referenced by concurrencyLimit().

template<typename T >
void LimitedTaskQueue::push ( 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 79 of file LimitedTaskQueue.h.

References m_queues, and lumiQueryAPI::q.

Referenced by LimitedTaskQueue(), and edm::Worker::TaskQueueAdaptor::push().

79  {
80  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
81  for(auto& q: m_queues) {
82  q.push([set_to_run,iAction]() {
83  bool expected = false;
84  if(set_to_run->compare_exchange_strong(expected,true)) {
85  iAction();
86  }
87  });
88  }
89  }
std::vector< SerialTaskQueue > m_queues
template<typename T >
void LimitedTaskQueue::pushAndWait ( const T iAction)

synchronously pushes functor iAction into queue

The function will wait until iAction has completed before returning. If another task is already running on the queue, the system is allowed to find another TBB task to execute while waiting for the iAction to finish. In that way the core is not idled while waiting.

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

Definition at line 92 of file LimitedTaskQueue.h.

References pyrootRender::destroy(), m_queues, and lumiQueryAPI::q.

Referenced by LimitedTaskQueue(), and edm::Worker::TaskQueueAdaptor::pushAndWait().

92  {
93  tbb::empty_task* waitTask = new (tbb::task::allocate_root()) tbb::empty_task;
94  waitTask->set_ref_count(2);
95  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
96  for(auto& q: m_queues) {
97  q.push([set_to_run,waitTask,iAction]() {
98  bool expected = false;
99  if(set_to_run->compare_exchange_strong(expected,true)) {
100  try {
101  iAction();
102  }catch(...) {}
103  waitTask->decrement_ref_count();
104  }
105  });
106  }
107  waitTask->wait_for_all();
108  tbb::task::destroy(*waitTask);
109  }
def destroy(e)
Definition: pyrootRender.py:13
std::vector< SerialTaskQueue > m_queues

Member Data Documentation

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

Definition at line 75 of file LimitedTaskQueue.h.

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