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 
38  public:
39  friend class WaitingTaskList;
40  friend class WaitingTaskHolder;
42 
44  WaitingTask() : m_ptr{nullptr} {}
45  ~WaitingTask() override {
46  delete m_ptr.load();
47  };
48 
49  // ---------- const member functions ---------------------------
50 
52 
54  std::exception_ptr const * exceptionPtr() const {
55  return m_ptr.load();
56  }
57  private:
58 
60 
64  void dependentTaskFailed(std::exception_ptr iPtr) {
65  if (iPtr and not m_ptr) {
66  auto temp = std::make_unique<std::exception_ptr>(iPtr);
67  std::exception_ptr* expected = nullptr;
68  if( m_ptr.compare_exchange_strong(expected, temp.get()) ) {
69  temp.release();
70  }
71  }
72  }
73 
74  std::atomic<std::exception_ptr*> m_ptr;
75  };
76 
77  template<typename F>
79  public:
80  explicit FunctorWaitingTask( F f): func_(f) {}
81 
82  task* execute() override {
83  func_(exceptionPtr());
84  return nullptr;
85  };
86 
87  private:
88  F func_;
89  };
90 
91  template< typename ALLOC, typename F>
93  return new (iAlloc) FunctorWaitingTask<F>(f);
94  }
95 
96 }
97 
98 #endif
~WaitingTask() override
Definition: WaitingTask.h:45
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:64
task * execute() override
Definition: WaitingTask.h:82
double f[11][100]
WaitingTask()
Constructor.
Definition: WaitingTask.h:44
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:92
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:54
std::atomic< std::exception_ptr * > m_ptr
Definition: WaitingTask.h:74