TimerSource.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Scheduler_TimerSource_
18 #define HH_SENF_Scheduler_TimerSource_ 1
19 
20 // Custom includes
21 #include <signal.h>
22 #include <boost/noncopyable.hpp>
23 #include "ClockService.hh"
24 #include "FdManager.hh"
25 
26 //#include "TimerSource.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 namespace scheduler {
31 namespace detail {
32 
34  : boost::noncopyable
35  {
36  public:
37  virtual ~TimerSource();
38 
39  virtual void timeout(ClockService::clock_type const & timeout) = 0;
40  virtual void notimeout() = 0;
41 
42  virtual void enable() = 0;
43  virtual void disable() = 0;
44 
45  protected:
46  TimerSource();
47  };
48 
50  : public detail::FdManager::Event, public TimerSource
51  {
52  public:
55 
56  virtual void timeout(ClockService::clock_type const & timeout);
57  virtual void notimeout();
58 
59  virtual void enable();
60  virtual void disable();
61 
62  private:
63  static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
64  virtual void signal(int events);
65  void reschedule();
66 
67  bool timeoutEnabled_;
68  ClockService::clock_type timeout_;
69  int timerPipe_[2];
70  sigset_t sigSet_;
71  bool signalEnabled_;
72  timer_t timerId_;
73  };
74 
76  : public TimerSource
77  {
78  public:
79  virtual void timeout(ClockService::clock_type const & timeout);
80  virtual void notimeout();
81 
82  virtual void enable();
83  virtual void disable();
84  };
85 
86 #ifdef HAVE_TIMERFD_CREATE
87  class TimerFDTimerSource
88  : public detail::FdManager::Event, public TimerSource
89  {
90  public:
91  TimerFDTimerSource();
92  ~TimerFDTimerSource();
93 
94  virtual void timeout(ClockService::clock_type const & timeout);
95  virtual void notimeout();
96 
97  virtual void enable();
98  virtual void disable();
99 
100  static bool haveTimerFD();
101 
102  private:
103  virtual void signal(int events);
104  void reschedule();
105 
106  int timerfd_;
107  bool timeoutEnabled_;
108  ClockService::clock_type timeout_;
109  };
110 #endif
111 
112 }}}
113 
114 //-/////////////////////////////////////////////////////////////////////////////////////////////////
115 #include "TimerSource.cci"
116 //#include "TimerSource.ct"
117 //#include "TimerSource.cti"
118 #endif
119 
120 
121 // Local Variables:
122 // mode: c++
123 // fill-column: 100
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"
129 // End:
config::time_type clock_type
ClockService timer data type.
Definition: ClockService.hh:78
StatsDataCollectorKernel signal
FdManager public header.
ClockService public header.
virtual void timeout(ClockService::clock_type const &timeout)=0