CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WaitingTaskHolder.h
Go to the documentation of this file.
1 #ifndef FWCore_Concurrency_WaitingTaskHolder_h
2 #define FWCore_Concurrency_WaitingTaskHolder_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Concurrency
6 // Class : WaitingTaskHolder
7 //
16 //
17 // Original Author: FWCore
18 // Created: Fri, 18 Nov 2016 20:30:42 GMT
19 //
20 
21 // system include files
22 #include <cassert>
23 #include "tbb/task_group.h"
24 
25 // user include files
28 
29 // forward declarations
30 
31 namespace edm {
33  public:
34  friend class WaitingTaskList;
36 
37  WaitingTaskHolder() : m_task(nullptr), m_group(nullptr) {}
38 
39  explicit WaitingTaskHolder(tbb::task_group& iGroup, edm::WaitingTask* iTask) : m_task(iTask), m_group(&iGroup) {
41  }
43  if (m_task) {
44  doneWaiting(std::exception_ptr{});
45  }
46  }
47 
48  WaitingTaskHolder(const WaitingTaskHolder& iHolder) : m_task(iHolder.m_task), m_group(iHolder.m_group) {
50  }
51 
53  iOther.m_task = nullptr;
54  }
55 
57  WaitingTaskHolder tmp(iRHS);
58  std::swap(m_task, tmp.m_task);
60  return *this;
61  }
62 
65  std::swap(m_task, tmp.m_task);
67  return *this;
68  }
69 
70  // ---------- const member functions ---------------------
71  bool taskHasFailed() const noexcept { return m_task->exceptionPtr() != nullptr; }
72 
73  bool hasTask() const noexcept { return m_task != nullptr; }
77  CMS_SA_ALLOW tbb::task_group* group() const noexcept { return m_group; }
78  // ---------- static member functions --------------------
79 
80  // ---------- member functions ---------------------------
81 
87  void presetTaskAsFailed(std::exception_ptr iExcept) {
88  if (iExcept) {
89  m_task->dependentTaskFailed(iExcept);
90  }
91  }
92 
93  void doneWaiting(std::exception_ptr iExcept) {
94  if (iExcept) {
95  m_task->dependentTaskFailed(iExcept);
96  }
97  //task_group::run can run the task before we finish
98  // doneWaiting and some other thread might
99  // try to reuse this object. Resetting
100  // before spawn avoids problems
101  auto task = m_task;
102  m_task = nullptr;
103  if (0 == task->decrement_ref_count()) {
104  m_group->run([task]() {
105  TaskSentry s{task};
106  task->execute();
107  });
108  }
109  }
110 
111  private:
113  auto t = m_task;
114  m_task = nullptr;
115  return t;
116  }
117  // ---------- member data --------------------------------
119  tbb::task_group* m_group;
120  };
121 } // namespace edm
122 
123 #endif
#define CMS_SA_ALLOW
bool hasTask() const noexcept
void presetTaskAsFailed(std::exception_ptr iExcept)
WaitingTaskHolder & operator=(const WaitingTaskHolder &iRHS)
WaitingTaskHolder(WaitingTaskHolder &&iOther)
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
WaitingTask * release_no_decrement() noexcept
void doneWaiting(std::exception_ptr iExcept)
bool taskHasFailed() const noexcept
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def move
Definition: eostools.py:511
WaitingTaskHolder(tbb::task_group &iGroup, edm::WaitingTask *iTask)
WaitingTaskHolder(const WaitingTaskHolder &iHolder)
tbb::task_group * m_group
tbb::task_group * group() const noexcept
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
tmp
align.sh
Definition: createJobs.py:716
void increment_ref_count()
Definition: TaskBase.h:41
WaitingTaskHolder & operator=(WaitingTaskHolder &&iRHS)