CMS 3D CMS Logo

WaitingTask.h
Go to the documentation of this file.
1 #ifndef FWCore_Concurrency_WaitingTask_h
2 #define FWCore_Concurrency_WaitingTask_h
3 // -*- C++ -*-
4 //
5 // Package: Concurrency
6 // Class : WaitingTask
7 //
15 //
16 // Original Author: Chris Jones
17 // Created: Thu Feb 21 13:46:31 CST 2013
18 // $Id$
19 //
20 
21 // system include files
22 #include <atomic>
23 #include <exception>
24 #include <memory>
25 
26 // user include files
28 
29 // forward declarations
30 
31 namespace edm {
32  class WaitingTaskList;
33  class WaitingTaskHolder;
34  class WaitingTaskWithArenaHolder;
35 
36  class WaitingTask : public TaskBase {
37  public:
38  friend class WaitingTaskList;
39  friend class WaitingTaskHolder;
41 
43  WaitingTask() : m_ptr{nullptr} {}
44  ~WaitingTask() override { delete m_ptr.load(); };
45 
46  // ---------- const member functions ---------------------------
47 
49 
51  std::exception_ptr const* exceptionPtr() const { return m_ptr.load(); }
52 
53  private:
55 
59  void dependentTaskFailed(std::exception_ptr iPtr) {
60  if (iPtr and not m_ptr) {
61  auto temp = std::make_unique<std::exception_ptr>(iPtr);
62  std::exception_ptr* expected = nullptr;
63  if (m_ptr.compare_exchange_strong(expected, temp.get())) {
64  temp.release();
65  }
66  }
67  }
68 
69  std::atomic<std::exception_ptr*> m_ptr;
70  };
71 
76  class FinalWaitingTask : public WaitingTask {
77  public:
78  FinalWaitingTask() : m_done{false} {}
79 
80  void execute() final { m_done = true; }
81 
82  bool done() const { return m_done.load(); }
83 
84  private:
85  void recycle() final {}
86  std::atomic<bool> m_done;
87  };
88 
89  template <typename F>
91  public:
92  explicit FunctorWaitingTask(F f) : func_(std::move(f)) {}
93 
94  void execute() final { func_(exceptionPtr()); };
95 
96  private:
97  F func_;
98  };
99 
100  template <typename F>
102  return new FunctorWaitingTask<F>(std::move(f));
103  }
104 
105 } // namespace edm
106 
107 #endif
edm::WaitingTask::m_ptr
std::atomic< std::exception_ptr * > m_ptr
Definition: WaitingTask.h:69
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm::FinalWaitingTask::execute
void execute() final
Definition: WaitingTask.h:80
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::TaskBase
Definition: TaskBase.h:31
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::WaitingTask::~WaitingTask
~WaitingTask() override
Definition: WaitingTask.h:44
edm::FinalWaitingTask::recycle
void recycle() final
Definition: WaitingTask.h:85
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::WaitingTaskList
Definition: WaitingTaskList.h:84
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
edm::WaitingTask::exceptionPtr
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
edm::FinalWaitingTask::FinalWaitingTask
FinalWaitingTask()
Definition: WaitingTask.h:78
WaitingTaskHolder
edm::FinalWaitingTask::m_done
std::atomic< bool > m_done
Definition: WaitingTask.h:86
edm::FunctorWaitingTask::execute
void execute() final
Definition: WaitingTask.h:94
edm::WaitingTask::dependentTaskFailed
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:101
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:32
edm::FinalWaitingTask::done
bool done() const
Definition: WaitingTask.h:82
edm::FunctorWaitingTask::FunctorWaitingTask
FunctorWaitingTask(F f)
Definition: WaitingTask.h:92
WaitingTaskList
edm::FinalWaitingTask
Definition: WaitingTask.h:76
edm::WaitingTask
Definition: WaitingTask.h:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::WaitingTask::WaitingTask
WaitingTask()
Constructor.
Definition: WaitingTask.h:43
TaskBase.h
edm::FunctorWaitingTask::func_
F func_
Definition: WaitingTask.h:94
edm::FunctorWaitingTask
Definition: WaitingTask.h:90