The Gaudi Framework  master (f5098d57)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PeriodicAction.h
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 #pragma once
12 
13 #include <chrono>
14 #include <functional>
15 #include <future>
16 #include <thread>
17 
18 namespace Gaudi::Utils {
30  public:
31  using clock = std::chrono::system_clock;
32  using time_point = clock::time_point;
33  using callback_t = std::function<void()>;
34 
35  PeriodicAction( callback_t callback, std::chrono::milliseconds period_duration, bool autostart = true );
38 
40 
41  void start();
42  void stop();
43 
44  private:
45  std::thread m_thread;
46  std::promise<void> m_stop_thread;
48  std::chrono::milliseconds m_period_duration;
49  };
50 } // namespace Gaudi::Utils
Gaudi::Utils::PeriodicAction::stop
void stop()
Definition: PeriodicAction.cpp:41
Gaudi::Utils::PeriodicAction::~PeriodicAction
~PeriodicAction()
Definition: PeriodicAction.cpp:21
Gaudi::Utils::PeriodicAction::m_stop_thread
std::promise< void > m_stop_thread
Definition: PeriodicAction.h:46
Gaudi::Utils::PeriodicAction::m_period_duration
std::chrono::milliseconds m_period_duration
Definition: PeriodicAction.h:48
Gaudi::Utils
Definition: Property.h:648
Gaudi::Utils::PeriodicAction
Helper to periodically run asynchronous tasks.
Definition: PeriodicAction.h:29
Gaudi::Utils::PeriodicAction::PeriodicAction
PeriodicAction(callback_t callback, std::chrono::milliseconds period_duration, bool autostart=true)
Definition: PeriodicAction.cpp:16
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
Gaudi::Utils::PeriodicAction::operator=
PeriodicAction & operator=(PeriodicAction &&)=default
Gaudi::Utils::PeriodicAction::clock
std::chrono::system_clock clock
Definition: PeriodicAction.h:31
Gaudi::Utils::PeriodicAction::start
void start()
Definition: PeriodicAction.cpp:23
Gaudi::Utils::PeriodicAction::time_point
clock::time_point time_point
Definition: PeriodicAction.h:32
Gaudi::Utils::PeriodicAction::PeriodicAction
PeriodicAction(PeriodicAction &&)=default
Gaudi::Utils::PeriodicAction::callback_t
std::function< void()> callback_t
Definition: PeriodicAction.h:33
gaudirun.callback
callback
Definition: gaudirun.py:202