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 #include "tbb/task.h"
26 
27 // 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 tbb::task {
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 
72  template <typename F>
74  public:
75  explicit FunctorWaitingTask(F f) : func_(std::move(f)) {}
76 
77  task* execute() override {
78  func_(exceptionPtr());
79  return nullptr;
80  };
81 
82  private:
83  F func_;
84  };
85 
86  template <typename ALLOC, typename F>
88  return new (iAlloc) FunctorWaitingTask<F>(std::move(f));
89  }
90 
91 } // namespace edm
92 
93 #endif
~WaitingTask() override
Definition: WaitingTask.h:44
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
task * execute() override
Definition: WaitingTask.h:77
double f[11][100]
WaitingTask()
Constructor.
Definition: WaitingTask.h:43
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:87
HLT enums.
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
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
def move(src, dest)
Definition: eostools.py:511