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{} {}
44  ~WaitingTask() override{};
45 
46  // ---------- const member functions ---------------------------
47 
49 
51  std::exception_ptr exceptionPtr() const {
52  if (m_ptrSet == static_cast<unsigned char>(State::kSet)) {
53  return m_ptr;
54  }
55  return std::exception_ptr{};
56  }
57 
58  protected:
59  std::exception_ptr const& uncheckedExceptionPtr() const { return m_ptr; }
60 
61  private:
62  enum class State : unsigned char { kUnset = 0, kSetting = 1, kSet = 2 };
64 
68  void dependentTaskFailed(std::exception_ptr iPtr) {
69  unsigned char isSet = static_cast<unsigned char>(State::kUnset);
70  if (iPtr and m_ptrSet.compare_exchange_strong(isSet, static_cast<unsigned char>(State::kSetting))) {
71  m_ptr = iPtr;
72  m_ptrSet = static_cast<unsigned char>(State::kSet);
73  }
74  }
75 
76  std::exception_ptr m_ptr;
77  std::atomic<unsigned char> m_ptrSet = static_cast<unsigned char>(State::kUnset);
78  };
79 
80  template <typename F>
82  public:
83  explicit FunctorWaitingTask(F f) : func_(std::move(f)) {}
84 
85  void execute() final { func_(uncheckedExceptionPtr() ? &uncheckedExceptionPtr() : nullptr); };
86 
87  private:
88  F func_;
89  };
90 
91  template <typename F>
93  return new FunctorWaitingTask<F>(std::move(f));
94  }
95 
96 } // namespace edm
97 
98 #endif
~WaitingTask() override
Definition: WaitingTask.h:44
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:68
std::exception_ptr exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
void execute() final
Definition: WaitingTask.h:85
std::atomic< unsigned char > m_ptrSet
Definition: WaitingTask.h:77
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:92
double f[11][100]
WaitingTask()
Constructor.
Definition: WaitingTask.h:43
std::exception_ptr const & uncheckedExceptionPtr() const
Definition: WaitingTask.h:59
std::exception_ptr m_ptr
Definition: WaitingTask.h:76
HLT enums.
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
def move(src, dest)
Definition: eostools.py:511