The Gaudi Framework  master (53dee381)
Loading...
Searching...
No Matches
AsynchronousAlgorithm.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 2023-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#pragma once
12
13#include <Gaudi/Algorithm.h>
14#include <Gaudi/Property.h>
15#include <GaudiKernel/Guards.h>
17
18#include <boost/fiber/fss.hpp> // for fiber_specific_ptr
19#include <boost/fiber/operations.hpp> // for this_fiber
20#include <chrono>
21
22namespace Gaudi {
32
34 public:
36 StatusCode sysInitialize() override;
37 StatusCode sysExecute( const EventContext& ctx ) override;
38
40 [[deprecated( "Wrap suspending or possibly suspending calls with `decorateSuspension` instead of following them "
41 "with a call to `restoreAfterSuspend`." )]] virtual StatusCode
42 restoreAfterSuspend() const;
43
46 StatusCode decorateSuspension( std::function<StatusCode()> f ) const;
47
49 StatusCode yield() const;
50
52 template <typename Clock, typename Duration>
53 StatusCode sleep_until( std::chrono::time_point<Clock, Duration> const& sleep_time ) const {
54 return decorateSuspension( [sleep_time]() {
55 boost::this_fiber::sleep_until( sleep_time );
57 } );
58 }
59
61 template <typename Rep, typename Period>
62 StatusCode sleep_for( std::chrono::duration<Rep, Period> const& dur ) const {
63 return decorateSuspension( [dur]() {
64 boost::this_fiber::sleep_for( dur );
66 } );
67 }
68
69 protected:
70 virtual StatusCode preSuspension() const;
71 virtual StatusCode postResumption() const;
72
73 private:
75 boost::fibers::fiber_specific_ptr<EventContext> s_ctx{};
76 mutable boost::fibers::fiber_specific_ptr<ITimelineSvc::TimelineRecorder> s_timelineRecorder{};
77
78 // Flag to control asynchronous timeline recording
79 bool m_doAsyncTimeline{ false };
80
83 "trigger auditor on suspension of execution" };
84 };
85} // namespace Gaudi
#define GAUDI_API
Definition Kernel.h:49
This class represents an entry point to all the event specific data.
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:87
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Base class for asynchronous algorithms.
Gaudi::Property< bool > m_auditorSuspension
boost::fibers::fiber_specific_ptr< EventContext > s_ctx
Contains current slot.
StatusCode sleep_until(std::chrono::time_point< Clock, Duration > const &sleep_time) const
Forwards to boost::this_fiber::sleep_until.
StatusCode sysExecute(const EventContext &ctx) override
virtual StatusCode restoreAfterSuspend() const
Restore after suspend.
StatusCode yield() const
Forwards to boost::this_fiber::yield.
StatusCode decorateSuspension(std::function< StatusCode()> f) const
Decorate a direct call to a suspending (or possibly suspending) function with the necessary pre- and ...
StatusCode sleep_for(std::chrono::duration< Rep, Period > const &dur) const
Forwards to boost::this_fiber::sleep_for.
boost::fibers::fiber_specific_ptr< ITimelineSvc::TimelineRecorder > s_timelineRecorder
Implementation of property with value of concrete type.
Definition Property.h:35
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
bool getDefaultAuditorValue(ISvcLocator *loc)
Definition Algorithm.cpp:44
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1