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() = default;
110 
111  // ---------- member functions ---------------------------
112 
118  void presetTaskAsFailed(std::exception_ptr iExcept);
119 
121 
126  void add(WaitingTask*);
127 
129 
135  void doneWaiting(std::exception_ptr iPtr);
136 
138 
143  void reset();
144 
145  private:
146  WaitingTaskList(const WaitingTaskList&) = delete; // stop default
147  const WaitingTaskList& operator=(const WaitingTaskList&) = delete; // stop default
148 
152  void announce();
153 
154  struct WaitNode {
156  std::atomic<WaitNode*> m_next;
158 
159  void setNextNode(WaitNode* iNext) { m_next = iNext; }
160 
161  WaitNode* nextNode() const { return m_next; }
162  };
163 
165 
166  // ---------- member data --------------------------------
167  std::atomic<WaitNode*> m_head;
168  std::unique_ptr<WaitNode[]> m_nodeCache;
169  CMS_THREAD_GUARD(m_waiting) std::exception_ptr m_exceptionPtr;
170  unsigned int m_nodeCacheSize;
171  std::atomic<unsigned int> m_lastAssignedCacheIndex;
172  std::atomic<bool> m_waiting;
173  };
174 } // namespace edm
175 
176 #endif
tbb::task * execute() override
def destroy(e)
Definition: pyrootRender.py:15
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:38
HLT enums.
void setNextNode(WaitNode *iNext)
void reset(double vett[256])
Definition: TPedValues.cc:11