YARP
Yet Another Robot Platform
PeriodicThread.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_PERIODICTHREAD_H
8 #define YARP_OS_PERIODICTHREAD_H
9 
10 #include <yarp/os/api.h>
11 #include <yarp/os/Time.h>
12 
13 namespace yarp {
14 namespace os {
15 
17 {
18  Relative,
19  Absolute
20 };
21 
28 {
29 public:
44  explicit PeriodicThread(double period,
47 
60  explicit PeriodicThread(double period, PeriodicThreadClock clockAccuracy);
61 
62  virtual ~PeriodicThread();
63 
68  bool start();
69 
75  void step();
76 
83  void stop();
84 
89  void askToStop();
90 
94  bool isRunning() const;
95 
99  bool isSuspended() const;
100 
106  bool setPeriod(double period);
107 
112  double getPeriod() const;
113 
118  void suspend();
119 
123  void resume();
124 
128  void resetStat();
129 
133  double getEstimatedPeriod() const;
134 
140  void getEstimatedPeriod(double& av, double& std) const;
141 
145  unsigned int getIterations() const;
146 
151  double getEstimatedUsed() const;
152 
158  void getEstimatedUsed(double& av, double& std) const;
159 
173  int setPriority(int priority, int policy = -1);
174 
179  int getPriority() const;
180 
185  int getPolicy() const;
186 
187 protected:
199  virtual bool threadInit();
200 
207  virtual void threadRelease();
208 
220  virtual void run() = 0;
221 
226  virtual void beforeStart();
227 
233  virtual void afterStart(bool success);
234 
235 #ifndef DOXYGEN_SHOULD_SKIP_THIS
236 private:
237  class Private;
238  Private* mPriv;
239 #endif // DOXYGEN_SHOULD_SKIP_THIS
240 };
241 
242 } // namespace os
243 } // namespace yarp
244 
245 #endif // YARP_OS_PERIODICTHREAD_H
An abstraction for a periodic thread.
virtual void run()=0
Loop function.
void useSystemClock()
Configure YARP to use system time (this is the default).
Definition: Time.cpp:144
ShouldUseSystemClock
Definition: Time.h:20
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18