The Gaudi Framework
master (53dee381)
Toggle main menu visibility
Loading...
Searching...
No Matches
AsyncSleeperAlg.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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/AsynchronousAlgorithm.h
>
12
#include <
Gaudi/Property.h
>
13
#include <chrono>
14
15
namespace
Gaudi::TestSuite
{
16
class
AsyncSleeperAlg
:
public
Gaudi::AsynchronousAlgorithm
{
17
public
:
18
using
Gaudi::AsynchronousAlgorithm::AsynchronousAlgorithm;
19
StatusCode
execute
(
const
EventContext
& )
const override
{
20
// Normal blocking sleep for the specified duration to simulate work being done
21
std::this_thread::sleep_for( std::chrono::microseconds(
m_sleepDuration
.value() ) );
22
info
() <<
"Will suspend execution with a sleep "
<<
m_sleepNumber
.value() <<
" time(s), each for around "
23
<<
m_sleepDuration
.value() <<
" microseconds"
<<
endmsg
;
24
for
(
int
i = 0; i <
m_sleepNumber
.value(); ++i ) {
25
auto
start
= std::chrono::high_resolution_clock::now();
26
// Suspend the fiber for the specified duration to simulate asynchronous work being done
27
auto
sc =
sleep_for
( std::chrono::microseconds(
m_sleepDuration
.value() ) );
28
auto
stop
= std::chrono::high_resolution_clock::now();
29
if
( !sc ) {
30
error
() <<
"Failed to suspend execution: "
<< sc <<
endmsg
;
31
return
sc;
32
}
33
info
() <<
"Suspended execution for "
34
<< std::chrono::duration_cast<std::chrono::microseconds>(
stop
-
start
).count() <<
" microseconds"
35
<<
endmsg
;
36
// Normal blocking sleep for the specified duration to simulate work being done
37
std::this_thread::sleep_for( std::chrono::microseconds(
m_sleepDuration
.value() ) );
38
}
39
return
StatusCode::SUCCESS
;
40
}
41
42
private
:
43
Gaudi::Property<int>
m_sleepDuration
{
this
,
"SuspensionDuration"
, 100,
"Suspension duration in microseconds"
};
44
Gaudi::Property<int>
m_sleepNumber
{
this
,
"SuspensionPoints"
, 1,
"Number of suspension points"
};
45
};
46
DECLARE_COMPONENT
( AsyncSleeperAlg )
47
48
}
// namespace Gaudi::TestSuite
AsynchronousAlgorithm.h
Property.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:35
Gaudi::Algorithm::stop
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition
Algorithm.h:179
Gaudi::Algorithm::start
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition
Algorithm.h:177
Gaudi::AsynchronousAlgorithm
Base class for asynchronous algorithms.
Definition
AsynchronousAlgorithm.h:33
Gaudi::AsynchronousAlgorithm::sleep_for
StatusCode sleep_for(std::chrono::duration< Rep, Period > const &dur) const
Forwards to boost::this_fiber::sleep_for.
Definition
AsynchronousAlgorithm.h:62
Gaudi::Property
Implementation of property with value of concrete type.
Definition
Property.h:35
Gaudi::TestSuite::AsyncSleeperAlg
Definition
AsyncSleeperAlg.cpp:16
Gaudi::TestSuite::AsyncSleeperAlg::m_sleepNumber
Gaudi::Property< int > m_sleepNumber
Definition
AsyncSleeperAlg.cpp:44
Gaudi::TestSuite::AsyncSleeperAlg::execute
StatusCode execute(const EventContext &) const override
Definition
AsyncSleeperAlg.cpp:19
Gaudi::TestSuite::AsyncSleeperAlg::m_sleepDuration
Gaudi::Property< int > m_sleepDuration
Definition
AsyncSleeperAlg.cpp:43
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
Gaudi::TestSuite
Definition
ConditionAccessorHolder.h:21
GaudiTestSuite
src
AsyncAlgorithms
AsyncSleeperAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0