YARP
Yet Another Robot Platform
yarp::os::RateThreadWrapper Class Reference

This class takes a Runnable instance and wraps a thread around it. More...

#include <yarp/os/RateThread.h>

+ Inheritance diagram for yarp::os::RateThreadWrapper:

Public Member Functions

 RateThreadWrapper ()
 Default constructor. More...
 
 RateThreadWrapper (Runnable *helper)
 
 RateThreadWrapper (Runnable &helper)
 
virtual ~RateThreadWrapper ()
 
void detach ()
 
virtual bool attach (Runnable &helper)
 
virtual bool attach (Runnable *helper)
 
bool open (double framerate=-1, bool polling=false)
 
void close ()
 
void stop ()
 
void run () override
 Loop function. More...
 
bool threadInit () override
 Initialization method. More...
 
void threadRelease () override
 Release method. More...
 
void afterStart (bool success) override
 Called just after a new thread starts (or fails to start), this is executed by the same thread that calls start(). More...
 
void beforeStart () override
 Called just before a new thread starts. More...
 
RunnablegetAttachment () const
 
- Public Member Functions inherited from yarp::os::PeriodicThread
 PeriodicThread (double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No)
 Constructor. More...
 
virtual ~PeriodicThread ()
 
bool start ()
 Call this to start the thread. More...
 
void step ()
 Call this to "step" the thread rather than starting it. More...
 
void stop ()
 Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() called). More...
 
void askToStop ()
 Stop the thread. More...
 
bool isRunning () const
 Returns true when the thread is started, false otherwise. More...
 
bool isSuspended () const
 Returns true when the thread is suspended, false otherwise. More...
 
bool setPeriod (double period)
 Set the (new) period of the thread. More...
 
double getPeriod () const
 Return the current period of the thread. More...
 
void suspend ()
 Suspend the thread, the thread keeps running by doLoop is never executed. More...
 
void resume ()
 Resume the thread if previously suspended. More...
 
void resetStat ()
 Reset thread statistics. More...
 
double getEstimatedPeriod () const
 Return estimated period since last reset. More...
 
void getEstimatedPeriod (double &av, double &std) const
 Return estimated period since last reset. More...
 
unsigned int getIterations () const
 Return the number of iterations performed since last reset. More...
 
double getEstimatedUsed () const
 Return the estimated duration of the run() function since last reset. More...
 
void getEstimatedUsed (double &av, double &std) const
 Return estimated duration of the run() function since last reset. More...
 
int setPriority (int priority, int policy=-1)
 Set the priority and scheduling policy of the thread, if the OS supports that. More...
 
int getPriority () const
 Query the current priority of the thread, if the OS supports that. More...
 
int getPolicy () const
 Query the current scheduling policy of the thread, if the OS supports that. More...
 

Additional Inherited Members

Detailed Description

This class takes a Runnable instance and wraps a thread around it.

Deprecated:
since YARP 3.3

Definition at line 243 of file RateThread.h.

Constructor & Destructor Documentation

◆ RateThreadWrapper() [1/3]

RateThreadWrapper::RateThreadWrapper ( )

Default constructor.

Definition at line 168 of file RateThread.cpp.

◆ RateThreadWrapper() [2/3]

RateThreadWrapper::RateThreadWrapper ( Runnable helper)

Definition at line 176 of file RateThread.cpp.

◆ RateThreadWrapper() [3/3]

RateThreadWrapper::RateThreadWrapper ( Runnable helper)

Definition at line 183 of file RateThread.cpp.

◆ ~RateThreadWrapper()

RateThreadWrapper::~RateThreadWrapper ( )
virtual

Definition at line 190 of file RateThread.cpp.

Member Function Documentation

◆ afterStart()

void RateThreadWrapper::afterStart ( bool  success)
overridevirtual

Called just after a new thread starts (or fails to start), this is executed by the same thread that calls start().

Parameters
successtrue iff the new thread started successfully.

Reimplemented from yarp::os::PeriodicThread.

Definition at line 269 of file RateThread.cpp.

◆ attach() [1/2]

bool RateThreadWrapper::attach ( Runnable helper)
virtual

Definition at line 204 of file RateThread.cpp.

◆ attach() [2/2]

bool RateThreadWrapper::attach ( Runnable helper)
virtual

Definition at line 212 of file RateThread.cpp.

◆ beforeStart()

void RateThreadWrapper::beforeStart ( )
overridevirtual

Called just before a new thread starts.

This method is executed by the same thread that calls start().

Reimplemented from yarp::os::PeriodicThread.

Definition at line 276 of file RateThread.cpp.

◆ close()

void RateThreadWrapper::close ( )

Definition at line 237 of file RateThread.cpp.

◆ detach()

void RateThreadWrapper::detach ( )

Definition at line 195 of file RateThread.cpp.

◆ getAttachment()

Runnable * RateThreadWrapper::getAttachment ( ) const

Definition at line 283 of file RateThread.cpp.

◆ open()

bool RateThreadWrapper::open ( double  framerate = -1,
bool  polling = false 
)

Definition at line 220 of file RateThread.cpp.

◆ run()

void RateThreadWrapper::run ( )
overridevirtual

Loop function.

This is the thread itself. The thread calls the run() function every <period> ms. At the end of each run, the thread will sleep the amounth of time required, taking into account the time spent inside the loop function. Example: requested period is 10ms, the run() function take 3ms to be executed, the thread will sleep for 7ms.

Note: after each run is completed, the thread will call a yield() in order to facilitate other threads to run.

Implements yarp::os::PeriodicThread.

Definition at line 247 of file RateThread.cpp.

◆ stop()

void RateThreadWrapper::stop ( )

Definition at line 242 of file RateThread.cpp.

◆ threadInit()

bool RateThreadWrapper::threadInit ( )
overridevirtual

Initialization method.

The thread executes this function when it starts and before "run". This is a good place to perform initialization tasks that need to be done by the thread itself (device drivers initialization, memory allocation etc). If the function returns false the thread quits and never calls "run". The return value of threadInit() is notified to the class and passed as a parameter to afterStart(). Note that afterStart() is called by the same thread that is executing the "start" method.

Reimplemented from yarp::os::PeriodicThread.

Definition at line 254 of file RateThread.cpp.

◆ threadRelease()

void RateThreadWrapper::threadRelease ( )
overridevirtual

Release method.

The thread executes this function once when it exits, after the last "run". This is a good place to release resources that were initialized in threadInit() (release memory, and device driver resources).

Reimplemented from yarp::os::PeriodicThread.

Definition at line 262 of file RateThread.cpp.


The documentation for this class was generated from the following files: