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 {
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
edm::WaitingTask::m_ptr
std::atomic< std::exception_ptr * > m_ptr
Definition: WaitingTask.h:69
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm
HLT enums.
Definition: AlignableModifier.h:19
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::WaitingTask::~WaitingTask
~WaitingTask() override
Definition: WaitingTask.h:44
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::WaitingTaskList
Definition: WaitingTaskList.h:101
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:31
edm::WaitingTask::exceptionPtr
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
WaitingTaskHolder
edm::FunctorWaitingTask::execute
task * execute() override
Definition: WaitingTask.h:77
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:87
edm::WaitingTask::dependentTaskFailed
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:30
edm::FunctorWaitingTask::FunctorWaitingTask
FunctorWaitingTask(F f)
Definition: WaitingTask.h:75
WaitingTaskList
edm::WaitingTask
Definition: WaitingTask.h:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::WaitingTask::WaitingTask
WaitingTask()
Constructor.
Definition: WaitingTask.h:43
edm::FunctorWaitingTask::func_
F func_
Definition: WaitingTask.h:80
edm::FunctorWaitingTask
Definition: WaitingTask.h:73