YARP
Yet Another Robot Platform
RateThread.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_RATETHREAD_H
11 #define YARP_OS_RATETHREAD_H
12 
13 #include <yarp/conf/system.h>
14 
15 #if !defined(YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE)
16 YARP_COMPILER_WARNING("<yarp/os/RateThread.h> file is deprecated")
17 #endif
18 
19 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0 (RateThreadWrapper since YARP 3.3)
22 
23 #include <yarp/os/api.h>
24 
25 #include <yarp/os/PeriodicThread.h>
26 #include <yarp/os/Runnable.h>
27 
28 namespace yarp {
29 namespace os {
30 
39 {
40 public:
49  RateThread(int period);
50 
51  virtual ~RateThread();
52 
57  bool start();
58 
64  bool step();
65 
72  void stop();
73 
78  void askToStop();
79 
83  bool isRunning();
84 
88  bool isSuspended();
89 
95  bool setRate(int period);
100  double getRate();
101 
106  void suspend();
107 
111  void resume();
112 
116  void resetStat();
117 
121  double getEstPeriod();
122 
128  void getEstPeriod(double& av, double& std);
129 
133  unsigned int getIterations();
134 
139  double getEstUsed();
140 
146  void getEstUsed(double& av, double& std);
147 
161  int setPriority(int priority, int policy = -1);
162 
167  int getPriority();
168 
173  int getPolicy();
174 
175 protected:
187  bool threadInit() override;
188 
195  void threadRelease() override;
196 
208  void run() override = 0;
209 
214  void beforeStart() override;
215 
221  void afterStart(bool success) override;
222 };
223 
227 class YARP_os_DEPRECATED_API_MSG("Use PeriodicThread(..., == ShouldUseSystemClock::Yes) instead") SystemRateThread : public PeriodicThread
228 {
229 public:
230  SystemRateThread(int period);
231 
232  virtual ~SystemRateThread();
233 
234  bool stepSystem();
235 };
236 
237 
243 class YARP_os_DEPRECATED_API RateThreadWrapper : public PeriodicThread
244 {
245 private:
246  yarp::os::Runnable* helper;
247  bool owned;
248 
249 public:
253  RateThreadWrapper();
254  RateThreadWrapper(Runnable* helper);
255  RateThreadWrapper(Runnable& helper);
256 
257  virtual ~RateThreadWrapper();
258 
259  void detach();
260  virtual bool attach(Runnable& helper);
261  virtual bool attach(Runnable* helper);
262 
263  bool open(double framerate = -1, bool polling = false);
264  void close();
265  void stop();
266 
267  void run() override;
268  bool threadInit() override;
269  void threadRelease() override;
270  void afterStart(bool success) override;
271  void beforeStart() override;
272 
273  Runnable* getAttachment() const;
274 };
275 
276 } // namespace os
277 } // namespace yarp
278 
279 YARP_WARNING_POP
280 #endif // YARP_NO_DEPRECATED
281 
282 #endif // YARP_OS_RATETHREAD_H
yarp::os::RateThread::~RateThread
virtual ~RateThread()
YARP_WARNING_PUSH
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:334
yarp::os::ShouldUseSystemClock::No
@ No
Runnable.h
api.h
yarp::os::RateThread::run
void run() override=0
Loop function.
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
system.h
PeriodicThread.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
YARP_os_DEPRECATED_API_MSG
#define YARP_os_DEPRECATED_API_MSG(X)
Definition: api.h:23
yarp::os::RateThread
An abstraction for a periodic thread.
Definition: RateThread.h:39
YARP_COMPILER_WARNING
#define YARP_COMPILER_WARNING(x)
Generate a warning at build time on supported compilers.
Definition: system.h:112
YARP_DISABLE_DEPRECATED_WARNING
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:336