geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
Waiter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef WAITER_HPP_INCLUDE
7 #define WAITER_HPP_INCLUDE
8 
9 #include <memory>
10 #include "geopm_time.h"
11 #include "geopm_public.h"
12 
13 namespace geopm
14 {
16  class GEOPM_PUBLIC Waiter
17  {
18  public:
21  static std::unique_ptr<Waiter> make_unique(double period);
25  static std::unique_ptr<Waiter> make_unique(double period,
26  std::string strategy);
27  Waiter() = default;
28  virtual ~Waiter() = default;
30  virtual void reset(void) = 0;
33  virtual void reset(double period) = 0;
36  virtual void wait(void) = 0;
39  virtual double period(void) const = 0;
40  };
41 
44  class GEOPM_PUBLIC SleepWaiter : public Waiter
45  {
46  public:
47  SleepWaiter(double period);
48  virtual ~SleepWaiter() = default;
49  void reset(void) override;
50  void reset(double period) override;
51  void wait(void) override;
52  double period(void) const override;
53  private:
54  double m_period;
55  geopm_time_s m_time_target;
56  bool m_is_first_time;
57  };
58 }
59 
60 #endif
Class to support a periodic wait loop based on clock_nanosleep() using CLOCK_REALTIME.
Definition: Waiter.hpp:45
virtual ~SleepWaiter()=default
Class to support a periodic wait loop.
Definition: Waiter.hpp:17
virtual void wait(void)=0
Wait until the period has elapsed since last call to reset() or wait()
virtual void reset(void)=0
Reset the timer for next wait.
virtual ~Waiter()=default
Waiter()=default
virtual double period(void) const =0
Get the period for the waiter.
virtual void reset(double period)=0
Reset the timer for next wait and set period.
Definition: Accumulator.cpp:12