CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
80 
81 // forward declarations
82 
83 namespace edm {
85  public:
87 
91  explicit WaitingTaskList(unsigned int iInitialSize = 2);
92  WaitingTaskList(const WaitingTaskList&) = delete; // stop default
93  const WaitingTaskList& operator=(const WaitingTaskList&) = delete; // stop default
94  ~WaitingTaskList() = default;
95 
96  // ---------- member functions ---------------------------
97 
103  void presetTaskAsFailed(std::exception_ptr iExcept);
104 
106 
111  void add(tbb::task_group*, WaitingTask*);
112 
114 
116  void add(WaitingTaskHolder);
117 
119 
125  void doneWaiting(std::exception_ptr iPtr);
126 
128 
133  void reset();
134 
135  private:
139  void announce();
140 
141  struct WaitNode {
143  tbb::task_group* m_group;
144  std::atomic<WaitNode*> m_next;
146 
147  void setNextNode(WaitNode* iNext) { m_next = iNext; }
148 
149  WaitNode* nextNode() const { return m_next; }
150  };
151 
152  WaitNode* createNode(tbb::task_group* iGroup, WaitingTask* iTask);
153 
154  // ---------- member data --------------------------------
155  std::atomic<WaitNode*> m_head;
156  std::unique_ptr<WaitNode[]> m_nodeCache;
158  unsigned int m_nodeCacheSize;
159  std::atomic<unsigned int> m_lastAssignedCacheIndex;
160  std::atomic<bool> m_waiting;
161  };
162 } // namespace edm
163 
164 #endif
std::atomic< bool > m_waiting
std::atomic< unsigned int > m_lastAssignedCacheIndex
std::atomic< WaitNode * > m_head
void reset()
Resets access to the resource so that added tasks will wait.
std::atomic< WaitNode * > m_next
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
std::unique_ptr< WaitNode[]> m_nodeCache
std::exception_ptr m_exceptionPtr
#define CMS_THREAD_GUARD(_var_)
WaitingTaskList(unsigned int iInitialSize=2)
Constructor.
void add(tbb::task_group *, WaitingTask *)
Adds task to the waiting list.
unsigned int m_nodeCacheSize
void presetTaskAsFailed(std::exception_ptr iExcept)
void setNextNode(WaitNode *iNext)
~WaitingTaskList()=default
const WaitingTaskList & operator=(const WaitingTaskList &)=delete
WaitNode * createNode(tbb::task_group *iGroup, WaitingTask *iTask)