CommonTools
Utils
interface
ThreadSafeFunctor.h
Go to the documentation of this file.
1
#ifndef CommonTools_Utils_ThreadSafeFunctor_H
2
#define CommonTools_Utils_ThreadSafeFunctor_H
3
4
#include "
FWCore/Utilities/interface/thread_safety_macros.h
"
5
6
#include <mutex>
7
#include <utility>
8
9
// This class is a simple wrapper around some functor class to use its operator() in a thread-safe way.
10
11
template
<
class
Functor>
12
class
ThreadSafeFunctor
{
13
public
:
14
template
<
typename
... Params>
15
ThreadSafeFunctor
(Params&&...
params
) :
functor_
{std::forward<Params>(
params
)...} {}
16
17
ThreadSafeFunctor
(
ThreadSafeFunctor
&&
other
) noexcept :
functor_
(
std::move
(
other
.functor_)) {}
18
19
template
<
typename
... Params>
20
typename
std::invoke_result_t<Functor, Params...>
operator()
(Params&&...
params
)
const
{
21
std::lock_guard<std::mutex> guard(
mutex_
);
22
return
functor_
(std::forward<Params>(
params
)...);
23
}
24
25
private
:
26
const
Functor
functor_
;
27
CMS_THREAD_SAFE
mutable
std::mutex
mutex_
;
28
};
29
30
#endif
CalibrationSummaryClient_cfi.params
params
Definition:
CalibrationSummaryClient_cfi.py:14
ThreadSafeFunctor::functor_
const Functor functor_
Definition:
ThreadSafeFunctor.h:26
trackingPlots.other
other
Definition:
trackingPlots.py:1460
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition:
thread_safety_macros.h:4
ThreadSafeFunctor
Definition:
ThreadSafeFunctor.h:12
thread_safety_macros.h
mutex
static std::mutex mutex
Definition:
Proxy.cc:8
ThreadSafeFunctor::mutex_
std::mutex mutex_
Definition:
ThreadSafeFunctor.h:27
eostools.move
def move(src, dest)
Definition:
eostools.py:511
ThreadSafeFunctor::ThreadSafeFunctor
ThreadSafeFunctor(Params &&... params)
Definition:
ThreadSafeFunctor.h:15
ThreadSafeFunctor::operator()
std::invoke_result_t< Functor, Params... > operator()(Params &&... params) const
Definition:
ThreadSafeFunctor.h:20
ThreadSafeFunctor::ThreadSafeFunctor
ThreadSafeFunctor(ThreadSafeFunctor &&other) noexcept
Definition:
ThreadSafeFunctor.h:17
Generated for CMSSW Reference Manual by
1.8.16