CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
~WaitingTask() override
Definition: WaitingTask.h:44
void execute() final
Definition: WaitingTask.h:80
bool done() const
Definition: WaitingTask.h:82
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
void execute() final
Definition: WaitingTask.h:94
void recycle() final
Definition: WaitingTask.h:85
def move
Definition: eostools.py:511
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:101
WaitingTask()
Constructor.
Definition: WaitingTask.h:43
std::atomic< bool > m_done
Definition: WaitingTask.h:86
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
std::atomic< std::exception_ptr * > m_ptr
Definition: WaitingTask.h:69