DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dpdklibs
include
dpdklibs
sender
CallbackGate.hpp
Go to the documentation of this file.
1
28
#ifndef DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_CALLBACKGATE_HPP_
29
#define DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_CALLBACKGATE_HPP_
30
31
#include <mutex>
32
#include <shared_mutex>
33
#include <utility>
34
35
namespace
dunedaq::dpdklibs::sender
{
36
37
template
<
typename
Owner>
38
class
CallbackGate
39
{
40
public
:
41
CallbackGate
() =
default
;
42
CallbackGate
(
const
CallbackGate
&) =
delete
;
43
CallbackGate
&
operator=
(
const
CallbackGate
&) =
delete
;
44
CallbackGate
(
CallbackGate
&&) =
delete
;
45
CallbackGate
&
operator=
(
CallbackGate
&&) =
delete
;
46
47
void
arm
(Owner* owner)
48
{
49
std::unique_lock lock(
m_mutex
);
50
m_owner
= owner;
51
}
52
53
// Blocks until every in-flight dispatch() has returned, then disarms.
54
void
tombstone
()
55
{
56
std::unique_lock lock(
m_mutex
);
57
m_owner
=
nullptr
;
58
}
59
60
bool
armed
()
const
61
{
62
std::shared_lock lock(
m_mutex
);
63
return
m_owner
!=
nullptr
;
64
}
65
66
// Invoke fn(*owner) under a shared lock if armed. Returns true if fn ran.
67
// The shared lock guarantees the owner outlives the call with respect to
68
// tombstone(). It does not serialize concurrent dispatches.
69
template
<
typename
Fn>
70
bool
dispatch
(Fn&& fn)
71
{
72
std::shared_lock lock(
m_mutex
);
73
if
(
m_owner
==
nullptr
) {
74
return
false
;
75
}
76
std::forward<Fn>(fn)(*m_owner);
77
return
true
;
78
}
79
80
private
:
81
mutable
std::shared_mutex
m_mutex
;
82
Owner*
m_owner
=
nullptr
;
83
};
84
85
}
// namespace dunedaq::dpdklibs::sender
86
87
#endif
// DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_CALLBACKGATE_HPP_
dunedaq::dpdklibs::sender::CallbackGate::armed
bool armed() const
Definition
CallbackGate.hpp:60
dunedaq::dpdklibs::sender::CallbackGate::tombstone
void tombstone()
Definition
CallbackGate.hpp:54
dunedaq::dpdklibs::sender::CallbackGate::CallbackGate
CallbackGate()=default
dunedaq::dpdklibs::sender::CallbackGate::arm
void arm(Owner *owner)
Definition
CallbackGate.hpp:47
dunedaq::dpdklibs::sender::CallbackGate::operator=
CallbackGate & operator=(const CallbackGate &)=delete
dunedaq::dpdklibs::sender::CallbackGate::operator=
CallbackGate & operator=(CallbackGate &&)=delete
dunedaq::dpdklibs::sender::CallbackGate::CallbackGate
CallbackGate(CallbackGate &&)=delete
dunedaq::dpdklibs::sender::CallbackGate::m_mutex
std::shared_mutex m_mutex
Definition
CallbackGate.hpp:81
dunedaq::dpdklibs::sender::CallbackGate::dispatch
bool dispatch(Fn &&fn)
Definition
CallbackGate.hpp:70
dunedaq::dpdklibs::sender::CallbackGate::CallbackGate
CallbackGate(const CallbackGate &)=delete
dunedaq::dpdklibs::sender::CallbackGate::m_owner
Owner * m_owner
Definition
CallbackGate.hpp:82
dunedaq::dpdklibs::sender
Definition
CallbackGate.hpp:35
Generated on
for DUNE-DAQ by
1.18.0