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 {
93  tbb::task::destroy(*iTask);
94  }
95  };
96  }
98  inline std::unique_ptr<edm::EmptyWaitingTask, waitingtask::TaskDestroyer> make_empty_waiting_task() {
99  return std::unique_ptr<edm::EmptyWaitingTask, waitingtask::TaskDestroyer>( new (tbb::task::allocate_root()) edm::EmptyWaitingTask{});
100  }
101 
103  {
104 
105  public:
107 
111  explicit WaitingTaskList(unsigned int iInitialSize = 2);
112  ~WaitingTaskList() = default;
113 
114  // ---------- member functions ---------------------------
115 
121  void presetTaskAsFailed(std::exception_ptr iExcept);
122 
124 
129  void add(WaitingTask*);
130 
132 
138  void doneWaiting(std::exception_ptr iPtr);
139 
141 
146  void reset();
147 
148  private:
149  WaitingTaskList(const WaitingTaskList&) = delete; // stop default
150  const WaitingTaskList& operator=(const WaitingTaskList&) = delete; // stop default
151 
155  void announce();
156 
157  struct WaitNode {
159  std::atomic<WaitNode*> m_next;
161 
162  void setNextNode(WaitNode* iNext){
163  m_next = iNext;
164  }
165 
166  WaitNode* nextNode() const {
167  return m_next;
168  }
169  };
170 
172 
173 
174  // ---------- member data --------------------------------
175  std::atomic<WaitNode*> m_head;
176  std::unique_ptr<WaitNode[]> m_nodeCache;
177  CMS_THREAD_GUARD(m_waiting) std::exception_ptr m_exceptionPtr;
178  unsigned int m_nodeCacheSize;
179  std::atomic<unsigned int> m_lastAssignedCacheIndex;
180  std::atomic<bool> m_waiting;
181  };
182 }
183 
184 #endif
tbb::task * execute() override
def destroy(e)
Definition: pyrootRender.py:13
std::atomic< WaitNode * > m_head
std::atomic< WaitNode * > m_next
void operator()(tbb::task *iTask) const
std::unique_ptr< WaitNode[]> m_nodeCache
std::unique_ptr< edm::EmptyWaitingTask, waitingtask::TaskDestroyer > make_empty_waiting_task()
Create an EmptyWaitingTask which will properly be destroyed.
def createNode(xml_doc, node_name, values={}, parent=None)
#define CMS_THREAD_GUARD(_var_)
EmptyWaitingTask()=default
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
friend class WaitingTaskList
Definition: WaitingTask.h:39
HLT enums.
void setNextNode(WaitNode *iNext)
void reset(double vett[256])
Definition: TPedValues.cc:11