FWCore
Concurrency
interface
WaitingTaskWithArenaHolder.h
Go to the documentation of this file.
1
#ifndef FWCore_Concurrency_WaitingTaskWithArenaHolder_h
2
#define FWCore_Concurrency_WaitingTaskWithArenaHolder_h
3
// -*- C++ -*-
4
//
5
// Package: FWCore/Concurrency
6
// Class : WaitingTaskWithArenaHolder
7
//
17
//
18
// Original Author: W. David Dagenhart
19
// Created: 9 November 2017
20
//
21
22
#include <exception>
23
#include <memory>
24
25
#include "tbb/task_arena.h"
26
27
namespace
edm
{
28
class
WaitingTask
;
29
class
WaitingTaskHolder
;
30
31
class
WaitingTaskWithArenaHolder
{
32
public
:
33
WaitingTaskWithArenaHolder
();
34
35
// Note that the arena will be the one containing the thread
36
// that runs this constructor. This is the arena where you
37
// eventually intend for the task to be spawned.
38
explicit
WaitingTaskWithArenaHolder
(
WaitingTask
* iTask);
39
40
~WaitingTaskWithArenaHolder
();
41
42
WaitingTaskWithArenaHolder
(
WaitingTaskWithArenaHolder
const
& iHolder);
43
44
WaitingTaskWithArenaHolder
(
WaitingTaskWithArenaHolder
&& iOther);
45
46
WaitingTaskWithArenaHolder
&
operator=
(
const
WaitingTaskWithArenaHolder
& iRHS);
47
48
WaitingTaskWithArenaHolder
&
operator=
(
WaitingTaskWithArenaHolder
&& iRHS);
49
50
// This spawns the task. The arena is needed to get the task spawned
51
// into the correct arena of threads. Use of the arena allows doneWaiting
52
// to be called from a thread outside the arena of threads that will manage
53
// the task. doneWaiting can be called from a non-TBB thread.
54
void
doneWaiting
(std::exception_ptr iExcept);
55
56
// This next function is useful if you know from the context that
57
// m_arena (which is set when the constructor was executes) is the
58
// same arena in which you want to execute the doneWaiting function.
59
// It allows an optimization which avoids the enqueue step in the
60
// doneWaiting function.
61
//
62
// Be warned though that in general this function cannot be used.
63
// Spawning a task outside the correct arena could create a new separate
64
// arena with its own extra TBB worker threads if this function is used
65
// in an inappropriate context (and silently such that you might not notice
66
// the problem quickly).
67
WaitingTaskHolder
makeWaitingTaskHolderAndRelease
();
68
69
private
:
70
// ---------- member data --------------------------------
71
WaitingTask
*
m_task
;
72
std::shared_ptr<tbb::task_arena>
m_arena
;
73
};
74
75
template
<
typename
F>
76
auto
make_lambda_with_holder
(
WaitingTaskWithArenaHolder
h
,
F
&&
f
) {
77
return
[holder =
std::move
(
h
),
func
= std::forward<F>(
f
)]()
mutable
{
78
try
{
79
func
(holder);
80
}
catch
(...) {
81
holder.doneWaiting(std::current_exception());
82
}
83
};
84
}
85
86
template
<
typename
ALLOC,
typename
F>
87
auto
make_waiting_task_with_holder
(ALLOC&& iAlloc,
WaitingTaskWithArenaHolder
h
,
F
&&
f
) {
88
return
make_waiting_task
(
89
std::forward<ALLOC>(iAlloc),
90
[holder =
h
,
func
=
make_lambda_with_holder
(
h
, std::forward<F>(
f
))](std::exception_ptr
const
* excptr)
mutable
{
91
if
(excptr) {
92
holder.doneWaiting(*excptr);
93
return
;
94
}
95
func
();
96
});
97
}
98
}
// namespace edm
99
#endif
edm::WaitingTaskWithArenaHolder::operator=
WaitingTaskWithArenaHolder & operator=(const WaitingTaskWithArenaHolder &iRHS)
Definition:
WaitingTaskWithArenaHolder.cc:44
edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder
WaitingTaskWithArenaHolder()
Definition:
WaitingTaskWithArenaHolder.cc:16
f
double f[11][100]
Definition:
MuScleFitUtils.cc:78
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::WaitingTaskWithArenaHolder::m_task
WaitingTask * m_task
Definition:
WaitingTaskWithArenaHolder.h:71
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition:
blowfish.cc:163
edm::WaitingTaskWithArenaHolder::m_arena
std::shared_ptr< tbb::task_arena > m_arena
Definition:
WaitingTaskWithArenaHolder.h:72
edm::make_lambda_with_holder
auto make_lambda_with_holder(WaitingTaskWithArenaHolder h, F &&f)
Definition:
WaitingTaskWithArenaHolder.h:76
edm::WaitingTaskWithArenaHolder
Definition:
WaitingTaskWithArenaHolder.h:31
WaitingTask
edm::make_waiting_task_with_holder
auto make_waiting_task_with_holder(ALLOC &&iAlloc, WaitingTaskWithArenaHolder h, F &&f)
Definition:
WaitingTaskWithArenaHolder.h:87
WaitingTaskHolder
h
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition:
WaitingTask.h:87
edm::WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder
~WaitingTaskWithArenaHolder()
Definition:
WaitingTaskWithArenaHolder.cc:26
edm::WaitingTaskHolder
Definition:
WaitingTaskHolder.h:30
TrackCollections2monitor_cff.func
func
Definition:
TrackCollections2monitor_cff.py:359
edm::WaitingTask
Definition:
WaitingTask.h:36
eostools.move
def move(src, dest)
Definition:
eostools.py:511
edm::WaitingTaskWithArenaHolder::makeWaitingTaskHolderAndRelease
WaitingTaskHolder makeWaitingTaskHolderAndRelease()
Definition:
WaitingTaskWithArenaHolder.cc:91
edm::WaitingTaskWithArenaHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition:
WaitingTaskWithArenaHolder.cc:62
Generated for CMSSW Reference Manual by
1.8.16