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)
13YARP_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
23#include <yarp/os/Runnable.h>
24
25namespace yarp::os {
26
35{
36public:
45 RateThread(int period);
46
47 virtual ~RateThread();
48
53 bool start();
54
60 bool step();
61
68 void stop();
69
74 void askToStop();
75
79 bool isRunning();
80
84 bool isSuspended();
85
91 bool setRate(int period);
96 double getRate();
97
102 void suspend();
103
107 void resume();
108
112 void resetStat();
113
117 double getEstPeriod();
118
124 void getEstPeriod(double& av, double& std);
125
129 unsigned int getIterations();
130
135 double getEstUsed();
136
142 void getEstUsed(double& av, double& std);
143
157 int setPriority(int priority, int policy = -1);
158
163 int getPriority();
164
169 int getPolicy();
170
171protected:
183 bool threadInit() override;
184
191 void threadRelease() override;
192
204 void run() override = 0;
205
210 void beforeStart() override;
211
217 void afterStart(bool success) override;
218};
219
223class YARP_os_DEPRECATED_API_MSG("Use PeriodicThread(..., == ShouldUseSystemClock::Yes) instead") SystemRateThread : public PeriodicThread
224{
225public:
226 SystemRateThread(int period);
227
228 virtual ~SystemRateThread();
229
230 bool stepSystem();
231};
232
233
239class YARP_os_DEPRECATED_API RateThreadWrapper : public PeriodicThread
240{
241private:
242 yarp::os::Runnable* helper;
243 bool owned;
244
245public:
249 RateThreadWrapper();
250 RateThreadWrapper(Runnable* helper);
251 RateThreadWrapper(Runnable& helper);
252
253 virtual ~RateThreadWrapper();
254
255 void detach();
256 virtual bool attach(Runnable& helper);
257 virtual bool attach(Runnable* helper);
258
259 bool open(double framerate = -1, bool polling = false);
260 void close();
261 void stop();
262
263 void run() override;
264 bool threadInit() override;
265 void threadRelease() override;
266 void afterStart(bool success) override;
267 void beforeStart() override;
268
269 Runnable* getAttachment() const;
270};
271
272} // namespace yarp::os
273
274YARP_WARNING_POP
275#endif // YARP_NO_DEPRECATED
276
277#endif // YARP_OS_RATETHREAD_H
An abstraction for a periodic thread.
An abstraction for a periodic thread.
Definition: RateThread.h:35
void run() override=0
Loop function.
STL namespace.
An interface to the operating system, including Port based communication.
#define YARP_COMPILER_WARNING(x)
Generate a warning at build time on supported compilers.
Definition: system.h:111
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:333
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:335
#define YARP_os_DEPRECATED_API_MSG(X)
Definition: api.h:21