Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework
master (f31105fd)
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Typedefs
a
b
c
d
e
f
h
i
l
m
o
p
r
s
t
u
v
w
x
Enumerations
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
i
l
m
n
o
p
q
r
s
t
v
Enumerator
a
b
c
d
e
f
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Properties
Related Functions
:
a
b
c
d
e
g
h
i
m
o
p
r
s
t
v
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
_
b
c
e
f
g
h
i
l
m
n
o
p
r
s
t
u
z
Variables
a
b
c
d
e
g
h
i
m
o
p
q
r
s
t
v
x
Typedefs
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
w
Enumerations
Enumerator
c
e
f
p
u
v
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
PeriodicAction.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include <
Gaudi/Utils/PeriodicAction.h
>
12
#include <utility>
13
14
using
Gaudi::Utils::PeriodicAction
;
15
16
PeriodicAction::PeriodicAction(
callback_t
callback
,
std::chrono::milliseconds
period_duration,
bool
autostart )
17
: m_callback{
std::move
(
callback
) }, m_period_duration{ period_duration } {
18
if
( autostart )
start
();
19
}
20
21
PeriodicAction::~PeriodicAction
() {
stop
(); }
22
23
void
PeriodicAction::start
() {
24
if
( !
m_thread
.
joinable
() ) {
25
// Note: we can move the callback because we are not going to use it
26
// outside of the thread
27
m_thread
=
std::thread
{ [period_duration =
m_period_duration
,
callback
=
std::move
(
m_callback
),
28
stop_signal =
m_stop_thread
.
get_future
()] {
29
auto
next_call =
clock::now
() + period_duration;
30
while
( stop_signal.wait_until( next_call ) == std::future_status::timeout ) {
31
callback
();
32
// ensure the next call is at a multiple
33
// of m_period_duration after the last one
34
const
auto
now =
clock::now
();
35
while
( next_call < now ) next_call += period_duration;
36
}
37
} };
38
}
39
}
40
41
void
PeriodicAction::stop
() {
42
if
(
m_thread
.
joinable
() ) {
43
m_stop_thread
.
set_value
();
44
m_thread
.
join
();
45
}
46
}
Gaudi::Utils::PeriodicAction::stop
void stop()
Definition:
PeriodicAction.cpp:41
Gaudi::Utils::PeriodicAction::~PeriodicAction
~PeriodicAction()
Definition:
PeriodicAction.cpp:21
std::move
T move(T... args)
Gaudi::Utils::PeriodicAction::m_stop_thread
std::promise< void > m_stop_thread
Definition:
PeriodicAction.h:46
std::chrono::milliseconds
std::promise::set_value
T set_value(T... args)
std::function< void()>
Gaudi::Utils::PeriodicAction::m_period_duration
std::chrono::milliseconds m_period_duration
Definition:
PeriodicAction.h:48
std::promise::get_future
T get_future(T... args)
IOTest.start
start
Definition:
IOTest.py:110
std::thread::joinable
T joinable(T... args)
Gaudi::Utils::PeriodicAction
Helper to periodically run asynchronous tasks.
Definition:
PeriodicAction.h:29
std::thread
STL class.
Gaudi::Utils::PeriodicAction::m_callback
callback_t m_callback
Definition:
PeriodicAction.h:47
Gaudi::Utils::PeriodicAction::m_thread
std::thread m_thread
Definition:
PeriodicAction.h:45
PeriodicAction.h
Gaudi::Utils::PeriodicAction::start
void start()
Definition:
PeriodicAction.cpp:23
std::thread::join
T join(T... args)
gaudirun.callback
callback
Definition:
gaudirun.py:202
std::chrono::system_clock::now
T now(T... args)
GaudiUtils
src
Lib
PeriodicAction.cpp
Generated on Mon Apr 7 2025 16:26:26 for The Gaudi Framework by
1.8.18