CMS 3D CMS Logo

WaitingTaskList.h
Go to the documentation of this file.
1 #ifndef FWCore_Concurrency_WaitingTaskList_h
2 #define FWCore_Concurrency_WaitingTaskList_h
3 // -*- C++ -*-
4 //
5 // Package: Concurrency
6 // Class : WaitingTaskList
7 //
67 //
68 // Original Author: Chris Jones
69 // Created: Thu Feb 21 13:46:31 CST 2013
70 // $Id$
71 //
72 
73 // system include files
74 #include <atomic>
75 
76 // user include files
79 
80 // forward declarations
81 
82 namespace edm {
83  class EmptyWaitingTask : public WaitingTask {
84  public:
85  EmptyWaitingTask() = default;
86 
87  tbb::task* execute() override { return nullptr; }
88  };
89 
90  namespace waitingtask {
91  struct TaskDestroyer {
92  void operator()(tbb::task* iTask) const { tbb::task::destroy(*iTask); }
93  };
94  } // namespace waitingtask
96  inline std::unique_ptr<edm::EmptyWaitingTask, waitingtask::TaskDestroyer> make_empty_waiting_task() {
97  return std::unique_ptr<edm::EmptyWaitingTask, waitingtask::TaskDestroyer>(new (tbb::task::allocate_root())
99  }
100 
102  public:
104 
108  explicit WaitingTaskList(unsigned int iInitialSize = 2);
109  WaitingTaskList(const WaitingTaskList&) = delete; // stop default
110  const WaitingTaskList& operator=(const WaitingTaskList&) = delete; // stop default
111  ~WaitingTaskList() = default;
112 
113  // ---------- member functions ---------------------------
114 
120  void presetTaskAsFailed(std::exception_ptr iExcept);
121 
123 
128  void add(WaitingTask*);
129 
131 
137  void doneWaiting(std::exception_ptr iPtr);
138 
140 
145  void reset();
146 
147  private:
151  void announce();
152 
153  struct WaitNode {
155  std::atomic<WaitNode*> m_next;
157 
158  void setNextNode(WaitNode* iNext) { m_next = iNext; }
159 
160  WaitNode* nextNode() const { return m_next; }
161  };
162 
163  WaitNode* createNode(WaitingTask* iTask);
164 
165  // ---------- member data --------------------------------
166  std::atomic<WaitNode*> m_head;
167  std::unique_ptr<WaitNode[]> m_nodeCache;
169  unsigned int m_nodeCacheSize;
170  std::atomic<unsigned int> m_lastAssignedCacheIndex;
171  std::atomic<bool> m_waiting;
172  };
173 } // namespace edm
174 
175 #endif
edm::waitingtask::TaskDestroyer::operator()
void operator()(tbb::task *iTask) const
Definition: WaitingTaskList.h:92
edm::WaitingTaskList::m_head
std::atomic< WaitNode * > m_head
Definition: WaitingTaskList.h:166
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EmptyWaitingTask::execute
tbb::task * execute() override
Definition: WaitingTaskList.h:87
edm::WaitingTaskList::add
void add(WaitingTask *)
Adds task to the waiting list.
Definition: WaitingTaskList.cc:90
edm::EmptyWaitingTask
Definition: WaitingTaskList.h:83
edm::WaitingTaskList::createNode
WaitNode * createNode(WaitingTask *iTask)
Definition: WaitingTaskList.cc:71
edm::WaitingTaskList::m_nodeCache
std::unique_ptr< WaitNode[]> m_nodeCache
Definition: WaitingTaskList.h:167
edm::WaitingTaskList::m_waiting
std::atomic< bool > m_waiting
Definition: WaitingTaskList.h:171
edm::WaitingTaskList::m_lastAssignedCacheIndex
std::atomic< unsigned int > m_lastAssignedCacheIndex
Definition: WaitingTaskList.h:170
edm::WaitingTaskList::WaitNode::m_next
std::atomic< WaitNode * > m_next
Definition: WaitingTaskList.h:155
edm::WaitingTaskList::reset
void reset()
Resets access to the resource so that added tasks will wait.
Definition: WaitingTaskList.cc:52
edm::WaitingTaskList
Definition: WaitingTaskList.h:101
edm::WaitingTaskList::presetTaskAsFailed
void presetTaskAsFailed(std::exception_ptr iExcept)
Definition: WaitingTaskList.cc:125
edm::waitingtask::TaskDestroyer
Definition: WaitingTaskList.h:91
edm::WaitingTaskList::WaitNode::m_fromCache
bool m_fromCache
Definition: WaitingTaskList.h:156
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::WaitingTaskList::doneWaiting
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
Definition: WaitingTaskList.cc:170
edm::WaitingTaskList::WaitNode::nextNode
WaitNode * nextNode() const
Definition: WaitingTaskList.h:160
edm::WaitingTaskList::~WaitingTaskList
~WaitingTaskList()=default
edm::EmptyWaitingTask::EmptyWaitingTask
EmptyWaitingTask()=default
thread_safety_macros.h
edm::WaitingTaskList::WaitNode::m_task
WaitingTask * m_task
Definition: WaitingTaskList.h:154
edm::WaitingTaskList::m_nodeCacheSize
unsigned int m_nodeCacheSize
Definition: WaitingTaskList.h:169
edm::WaitingTaskList::announce
void announce()
Definition: WaitingTaskList.cc:139
WaitingTask.h
edm::make_empty_waiting_task
std::unique_ptr< edm::EmptyWaitingTask, waitingtask::TaskDestroyer > make_empty_waiting_task()
Create an EmptyWaitingTask which will properly be destroyed.
Definition: WaitingTaskList.h:96
edm::WaitingTask
Definition: WaitingTask.h:36
edm::WaitingTaskList::WaitNode
Definition: WaitingTaskList.h:153
edm::WaitingTaskList::WaitingTaskList
WaitingTaskList(unsigned int iInitialSize=2)
Constructor.
Definition: WaitingTaskList.cc:37
edm::WaitingTaskList::m_exceptionPtr
std::exception_ptr m_exceptionPtr
Definition: WaitingTaskList.h:168
edm::WaitingTaskList::WaitNode::setNextNode
void setNextNode(WaitNode *iNext)
Definition: WaitingTaskList.h:158
edm::WaitingTaskList::operator=
const WaitingTaskList & operator=(const WaitingTaskList &)=delete
CMS_THREAD_GUARD
#define CMS_THREAD_GUARD(_var_)
Definition: thread_safety_macros.h:6