EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PeriodicThread.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CORE_PERIODICTHREAD_HPP_
2 #define ORG_EEROS_CORE_PERIODICTHREAD_HPP_
3 
4 #include <eeros/core/Thread.hpp>
6 #include <atomic>
7 
8 namespace eeros {
9 
10  class PeriodicThread : public Thread {
11 
12  public:
13  enum status { running = 0, stopping = 1, stopped = 2, paused = 3 };
14 
15  PeriodicThread(double period, double delay = 0, bool realtime = false, status start = running, int priority = 0);
16  virtual ~PeriodicThread();
17 
18  virtual status getStatus() const;
19  virtual double getPeriod() const;
20  virtual void start();
21  virtual void pause();
22  virtual void stop();
23 
24  static constexpr bool isRealtimeSupported() {
25  #ifdef REALTIME_SUPPORT
26  return true;
27  #else
28  return false;
29  #endif
30  }
31 
33 
34  private:
35  double period, delay;
36  bool rt;
37  std::atomic<status> s;
38 
39  static constexpr uint64_t to_ns(double s) { return static_cast<uint64_t>(s * 1000000000); }
40  static constexpr uint64_t to_us(double s) { return static_cast<uint64_t>(s * 1000000); }
41  static constexpr uint64_t to_ms(double s) { return static_cast<uint64_t>(s * 1000); }
42  };
43 };
44 
45 #endif // ORG_EEROS_CORE_PERIODICTHREAD_HPP_
Definition: PeriodicThread.hpp:13
Definition: PeriodicThread.hpp:13
Definition: PeriodicThread.hpp:10
Definition: PeriodicCounter.hpp:11
Definition: PeriodicThread.hpp:13
static constexpr bool isRealtimeSupported()
Definition: PeriodicThread.hpp:24
virtual void start()
PeriodicCounter counter
Definition: PeriodicThread.hpp:32
virtual double getPeriod() const
Definition: Thread.hpp:13
status
Definition: PeriodicThread.hpp:13
virtual void pause()
virtual void stop()
PeriodicThread(double period, double delay=0, bool realtime=false, status start=running, int priority=0)
Definition: PeriodicThread_POSIX.cpp:16
Definition: PeriodicThread.hpp:13
virtual status getStatus() const