forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitingTaskHolder.h
90 lines (72 loc) · 2.44 KB
/
WaitingTaskHolder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef FWCore_Concurrency_WaitingTaskHolder_h
#define FWCore_Concurrency_WaitingTaskHolder_h
// -*- C++ -*-
//
// Package: FWCore/Concurrency
// Class : WaitingTaskHolder
//
/**\class WaitingTaskHolder WaitingTaskHolder.h "WaitingTaskHolder.h"
Description: [one line class summary]
Usage:
<usage>
*/
//
// Original Author: FWCore
// Created: Fri, 18 Nov 2016 20:30:42 GMT
//
// system include files
#include <cassert>
// user include files
#include "Framework/WaitingTask.h"
// forward declarations
namespace edm {
class WaitingTaskHolder {
public:
WaitingTaskHolder() : m_task(nullptr) {}
explicit WaitingTaskHolder(edm::WaitingTask* iTask) : m_task(iTask) { m_task->increment_ref_count(); }
~WaitingTaskHolder() {
if (m_task) {
doneWaiting(std::exception_ptr{});
}
}
WaitingTaskHolder(const WaitingTaskHolder& iHolder) : m_task(iHolder.m_task) { m_task->increment_ref_count(); }
WaitingTaskHolder(WaitingTaskHolder&& iOther) : m_task(iOther.m_task) { iOther.m_task = nullptr; }
WaitingTaskHolder& operator=(const WaitingTaskHolder& iRHS) {
WaitingTaskHolder tmp(iRHS);
std::swap(m_task, tmp.m_task);
return *this;
}
// ---------- const member functions ---------------------
bool taskHasFailed() const { return m_task->exceptionPtr() != nullptr; }
// ---------- static member functions --------------------
// ---------- member functions ---------------------------
/** Use in the case where you need to inform the parent task of a
failure before some other child task which may be run later reports
a different, but related failure. You must later call doneWaiting
in the same thread passing the same exceptoin.
*/
void presetTaskAsFailed(std::exception_ptr iExcept) {
if (iExcept) {
m_task->dependentTaskFailed(iExcept);
}
}
void doneWaiting(std::exception_ptr iExcept) {
if (iExcept) {
m_task->dependentTaskFailed(iExcept);
}
//spawn can run the task before we finish
// doneWaiting and some other thread might
// try to reuse this object. Resetting
// before spawn avoids problems
auto task = m_task;
m_task = nullptr;
if (0 == task->decrement_ref_count()) {
tbb::task::spawn(*task);
}
}
private:
// ---------- member data --------------------------------
WaitingTask* m_task;
};
} // namespace edm
#endif