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 
24 // user include files
26 
27 // forward declarations
28 
29 namespace edm {
31  public:
33 
34  explicit WaitingTaskHolder(edm::WaitingTask* iTask) : m_task(iTask) { m_task->increment_ref_count(); }
36  if (m_task) {
37  doneWaiting(std::exception_ptr{});
38  }
39  }
40 
41  WaitingTaskHolder(const WaitingTaskHolder& iHolder) : m_task(iHolder.m_task) { m_task->increment_ref_count(); }
42 
43  WaitingTaskHolder(WaitingTaskHolder&& iOther) : m_task(iOther.m_task) { iOther.m_task = nullptr; }
44 
46  WaitingTaskHolder tmp(iRHS);
47  std::swap(m_task, tmp.m_task);
48  return *this;
49  }
50 
51  // ---------- const member functions ---------------------
52  bool taskHasFailed() const { return m_task->exceptionPtr() != nullptr; }
53 
54  // ---------- static member functions --------------------
55 
56  // ---------- member functions ---------------------------
57 
63  void presetTaskAsFailed(std::exception_ptr iExcept) {
64  if (iExcept) {
65  m_task->dependentTaskFailed(iExcept);
66  }
67  }
68 
69  void doneWaiting(std::exception_ptr iExcept) {
70  if (iExcept) {
71  m_task->dependentTaskFailed(iExcept);
72  }
73  //spawn can run the task before we finish
74  // doneWaiting and some other thread might
75  // try to reuse this object. Resetting
76  // before spawn avoids problems
77  auto task = m_task;
78  m_task = nullptr;
79  if (0 == task->decrement_ref_count()) {
80  tbb::task::spawn(*task);
81  }
82  }
83 
84  private:
85  // ---------- member data --------------------------------
87  };
88 } // namespace edm
89 
90 #endif
#define nullptr
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
void doneWaiting(std::exception_ptr iExcept)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
WaitingTaskHolder(const WaitingTaskHolder &iHolder)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
WaitingTaskHolder(edm::WaitingTask *iTask)
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51