The Gaudi Framework  master (e68eea06)
Loading...
Searching...
No Matches
PeriodicAction.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 2024-2025 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
18namespace Gaudi::Utils {
30 public:
31 using clock = std::chrono::steady_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,
36 unsigned int repetitions = 0 );
39
41
42 void start();
43 void stop();
44
45 private:
46 std::thread m_thread;
47 std::promise<void> m_stop_thread;
49 std::chrono::milliseconds m_period_duration;
50 unsigned int m_repetitions;
51 };
52} // namespace Gaudi::Utils
PeriodicAction(callback_t callback, std::chrono::milliseconds period_duration, bool autostart=true, unsigned int repetitions=0)
std::chrono::milliseconds m_period_duration
PeriodicAction & operator=(PeriodicAction &&)=default
std::promise< void > m_stop_thread
std::function< void()> callback_t
PeriodicAction(PeriodicAction &&)=default
std::chrono::steady_clock clock