CMS 3D CMS Logo

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 "oneapi/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(oneapi::tbb::task_group& iGroup, edm::WaitingTask* iTask)
40  : m_task(iTask), m_group(&iGroup) {
42  }
44  if (m_task) {
45  doneWaiting(std::exception_ptr{});
46  }
47  }
48 
49  WaitingTaskHolder(const WaitingTaskHolder& iHolder) : m_task(iHolder.m_task), m_group(iHolder.m_group) {
51  }
52 
54  iOther.m_task = nullptr;
55  }
56 
58  WaitingTaskHolder tmp(iRHS);
59  std::swap(m_task, tmp.m_task);
60  std::swap(m_group, tmp.m_group);
61  return *this;
62  }
63 
66  std::swap(m_task, tmp.m_task);
67  std::swap(m_group, tmp.m_group);
68  return *this;
69  }
70 
71  // ---------- const member functions ---------------------
72  bool taskHasFailed() const noexcept { return static_cast<bool>(m_task->exceptionPtr()); }
73 
74  bool hasTask() const noexcept { return m_task != nullptr; }
78  CMS_SA_ALLOW oneapi::tbb::task_group* group() const noexcept { return m_group; }
79  // ---------- static member functions --------------------
80 
81  // ---------- member functions ---------------------------
82 
88  void presetTaskAsFailed(std::exception_ptr iExcept) {
89  if (iExcept) {
90  m_task->dependentTaskFailed(iExcept);
91  }
92  }
93 
94  void doneWaiting(std::exception_ptr iExcept) {
95  if (iExcept) {
96  m_task->dependentTaskFailed(iExcept);
97  }
98  //task_group::run can run the task before we finish
99  // doneWaiting and some other thread might
100  // try to reuse this object. Resetting
101  // before spawn avoids problems
102  auto task = m_task;
103  m_task = nullptr;
104  if (0 == task->decrement_ref_count()) {
105  m_group->run([task]() {
106  TaskSentry s{task};
107  task->execute();
108  });
109  }
110  }
111 
112  private:
114  auto t = m_task;
115  m_task = nullptr;
116  return t;
117  }
118  // ---------- member data --------------------------------
120  oneapi::tbb::task_group* m_group;
121  };
122 } // namespace edm
123 
124 #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:68
oneapi::tbb::task_group * group() const noexcept
std::exception_ptr exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
WaitingTask * release_no_decrement() noexcept
void doneWaiting(std::exception_ptr iExcept)
oneapi::tbb::task_group * m_group
bool taskHasFailed() const noexcept
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
WaitingTaskHolder(const WaitingTaskHolder &iHolder)
WaitingTaskHolder(oneapi::tbb::task_group &iGroup, edm::WaitingTask *iTask)
HLT enums.
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511
void increment_ref_count()
Definition: TaskBase.h:41
WaitingTaskHolder & operator=(WaitingTaskHolder &&iRHS)