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