YARP
Yet Another Robot Platform
RateThread.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_RATETHREAD_H
8 #define YARP_OS_RATETHREAD_H
9 
10 #include <yarp/conf/system.h>
11 
12 #if !defined(YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE)
13 YARP_COMPILER_WARNING("<yarp/os/RateThread.h> file is deprecated")
14 #endif
15 
16 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0 (RateThreadWrapper since YARP 3.3)
19 
20 #include <yarp/os/api.h>
21 
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/Runnable.h>
24 
25 namespace yarp {
26 namespace os {
27 
36 {
37 public:
46  RateThread(int period);
47 
48  virtual ~RateThread();
49 
54  bool start();
55 
61  bool step();
62 
69  void stop();
70 
75  void askToStop();
76 
80  bool isRunning();
81 
85  bool isSuspended();
86 
92  bool setRate(int period);
97  double getRate();
98 
103  void suspend();
104 
108  void resume();
109 
113  void resetStat();
114 
118  double getEstPeriod();
119 
125  void getEstPeriod(double& av, double& std);
126 
130  unsigned int getIterations();
131 
136  double getEstUsed();
137 
143  void getEstUsed(double& av, double& std);
144 
158  int setPriority(int priority, int policy = -1);
159 
164  int getPriority();
165 
170  int getPolicy();
171 
172 protected:
184  bool threadInit() override;
185 
192  void threadRelease() override;
193 
205  void run() override = 0;
206 
211  void beforeStart() override;
212 
218  void afterStart(bool success) override;
219 };
220 
224 class YARP_os_DEPRECATED_API_MSG("Use PeriodicThread(..., == ShouldUseSystemClock::Yes) instead") SystemRateThread : public PeriodicThread
225 {
226 public:
227  SystemRateThread(int period);
228 
229  virtual ~SystemRateThread();
230 
231  bool stepSystem();
232 };
233 
234 
240 class YARP_os_DEPRECATED_API RateThreadWrapper : public PeriodicThread
241 {
242 private:
243  yarp::os::Runnable* helper;
244  bool owned;
245 
246 public:
250  RateThreadWrapper();
251  RateThreadWrapper(Runnable* helper);
252  RateThreadWrapper(Runnable& helper);
253 
254  virtual ~RateThreadWrapper();
255 
256  void detach();
257  virtual bool attach(Runnable& helper);
258  virtual bool attach(Runnable* helper);
259 
260  bool open(double framerate = -1, bool polling = false);
261  void close();
262  void stop();
263 
264  void run() override;
265  bool threadInit() override;
266  void threadRelease() override;
267  void afterStart(bool success) override;
268  void beforeStart() override;
269 
270  Runnable* getAttachment() const;
271 };
272 
273 } // namespace os
274 } // namespace yarp
275 
276 YARP_WARNING_POP
277 #endif // YARP_NO_DEPRECATED
278 
279 #endif // YARP_OS_RATETHREAD_H
An abstraction for a periodic thread.
An abstraction for a periodic thread.
Definition: RateThread.h:36
void run() override=0
Loop function.
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_COMPILER_WARNING(x)
Generate a warning at build time on supported compilers.
Definition: system.h:109
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:331
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:333
#define YARP_os_DEPRECATED_API_MSG(X)
Definition: api.h:21