The Gaudi Framework  master (53dee381)
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\***********************************************************************************/
12#include <Gaudi/Property.h>
13#include <chrono>
14
15namespace Gaudi::TestSuite {
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 }
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
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
This class represents an entry point to all the event specific data.
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition Algorithm.h:179
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition Algorithm.h:177
Base class for asynchronous algorithms.
StatusCode sleep_for(std::chrono::duration< Rep, Period > const &dur) const
Forwards to boost::this_fiber::sleep_for.
Implementation of property with value of concrete type.
Definition Property.h:35
Gaudi::Property< int > m_sleepNumber
StatusCode execute(const EventContext &) const override
Gaudi::Property< int > m_sleepDuration
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99