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

 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 operator=(), push(), and pushAndWait().

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

Member Function Documentation

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

Referenced by LimitedTaskQueue().

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 78 of file LimitedTaskQueue.h.

References m_queues, and lumiQueryAPI::q.

Referenced by LimitedTaskQueue().

78  {
79  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
80  for(auto& q: m_queues) {
81  q.push([set_to_run,iAction]() {
82  bool expected = false;
83  if(set_to_run->compare_exchange_strong(expected,true)) {
84  iAction();
85  }
86  });
87  }
88  }
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 91 of file LimitedTaskQueue.h.

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

Referenced by LimitedTaskQueue().

91  {
92  tbb::empty_task* waitTask = new (tbb::task::allocate_root()) tbb::empty_task;
93  waitTask->set_ref_count(2);
94  auto set_to_run = std::make_shared<std::atomic<bool>>(false);
95  for(auto& q: m_queues) {
96  q.push([set_to_run,waitTask,iAction]() {
97  bool expected = false;
98  if(set_to_run->compare_exchange_strong(expected,true)) {
99  try {
100  iAction();
101  }catch(...) {}
102  waitTask->decrement_ref_count();
103  }
104  });
105  }
106  waitTask->wait_for_all();
107  tbb::task::destroy(*waitTask);
108  }
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 74 of file LimitedTaskQueue.h.

Referenced by push(), and pushAndWait().