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:
32  WaitingTaskHolder() : m_task(nullptr) {}
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 
53  std::swap(m_task, tmp.m_task);
54  return *this;
55  }
56 
57  // ---------- const member functions ---------------------
58  bool taskHasFailed() const { return m_task->exceptionPtr() != nullptr; }
59 
60  // ---------- static member functions --------------------
61 
62  // ---------- member functions ---------------------------
63 
69  void presetTaskAsFailed(std::exception_ptr iExcept) {
70  if (iExcept) {
71  m_task->dependentTaskFailed(iExcept);
72  }
73  }
74 
75  void doneWaiting(std::exception_ptr iExcept) {
76  if (iExcept) {
77  m_task->dependentTaskFailed(iExcept);
78  }
79  //spawn can run the task before we finish
80  // doneWaiting and some other thread might
81  // try to reuse this object. Resetting
82  // before spawn avoids problems
83  auto task = m_task;
84  m_task = nullptr;
85  if (0 == task->decrement_ref_count()) {
86  tbb::task::spawn(*task);
87  }
88  }
89 
90  private:
91  // ---------- member data --------------------------------
93  };
94 } // namespace edm
95 
96 #endif
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::WaitingTaskHolder::WaitingTaskHolder
WaitingTaskHolder(WaitingTaskHolder &&iOther)
Definition: WaitingTaskHolder.h:43
edm::WaitingTaskHolder::operator=
WaitingTaskHolder & operator=(WaitingTaskHolder &&iRHS)
Definition: WaitingTaskHolder.h:51
edm::WaitingTaskHolder::m_task
WaitingTask * m_task
Definition: WaitingTaskHolder.h:92
edm::WaitingTaskHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition: WaitingTaskHolder.h:75
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::WaitingTaskHolder::~WaitingTaskHolder
~WaitingTaskHolder()
Definition: WaitingTaskHolder.h:35
edm::WaitingTaskHolder::presetTaskAsFailed
void presetTaskAsFailed(std::exception_ptr iExcept)
Definition: WaitingTaskHolder.h:69
edm::WaitingTask::exceptionPtr
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::WaitingTaskHolder::taskHasFailed
bool taskHasFailed() const
Definition: WaitingTaskHolder.h:58
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::WaitingTask::dependentTaskFailed
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
edm::WaitingTaskHolder::operator=
WaitingTaskHolder & operator=(const WaitingTaskHolder &iRHS)
Definition: WaitingTaskHolder.h:45
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:30
edm::WaitingTaskHolder::WaitingTaskHolder
WaitingTaskHolder(edm::WaitingTask *iTask)
Definition: WaitingTaskHolder.h:34
WaitingTask.h
edm::WaitingTask
Definition: WaitingTask.h:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::WaitingTaskHolder::WaitingTaskHolder
WaitingTaskHolder(const WaitingTaskHolder &iHolder)
Definition: WaitingTaskHolder.h:41
edm::WaitingTaskHolder::WaitingTaskHolder
WaitingTaskHolder()
Definition: WaitingTaskHolder.h:32