RTT::OS::PeriodicThread Class Reference

A PeriodicThread executes its step() method (or a RunnableInterface ) periodically. More...

#include <rtt/os/PeriodicThread.hpp>

Inheritance diagram for RTT::OS::PeriodicThread:
RTT::OS::ThreadInterface RTT::TimerThread RTT::SimulationThread

List of all members.

Public Member Functions

 PeriodicThread (int priority, const std::string &name, double period, OS::RunnableInterface *r=0)
 Create a Thread with a given priority and a name.
 PeriodicThread (int scheduler, int priority, const std::string &name, double period, OS::RunnableInterface *r=0)
 Create a Thread with a given scheduler type, priority and a name.
virtual bool run (OS::RunnableInterface *r)
 Run the functionality of one RunnableInterface object.
virtual bool start ()
 Start the Thread.
virtual bool stop ()
 Stop the Thread.
bool setPeriod (Seconds s)
 Set the periodicity in Seconds.
bool setPeriod (secs s, nsecs ns)
void getPeriod (secs &s, nsecs &ns) const
virtual Seconds getPeriod () const
 Get the periodicity in Seconds.
virtual nsecs getPeriodNS () const
 Get the periodicity in nanoseconds.
virtual bool isRunning () const
 Returns whether the thread is running.
virtual bool isActive () const
 Returns whether the thread is active.
virtual const char * getName () const
 Read the name of this task.
virtual RTOS_TASK * getTask ()
 Get the RTOS_TASK pointer.
virtual bool setScheduler (int sched_type)
 Change the scheduler policy in which this thread runs.
virtual int getScheduler () const
 Get the scheduler policy in which this thread runs.
bool setPeriod (TIME_SPEC p)
 Set the periodicity of this thread.
virtual bool setPriority (int priority)
 Set the priority of this Thread.
virtual int getPriority () const
 The priority of this Thread.
virtual void yield ()
 Yields (put to the back of the scheduler queue) the calling thread.
void setMaxOverrun (int m)
int getMaxOverrun () const
void terminate ()
 Exit and destroy the thread.
void emergencyStop ()
unsigned int threadNumber () const
 The unique thread number (within the same process).

Protected Member Functions

virtual void continuousStepping (bool yes_no)
virtual bool setToStop ()
 Use this from within step() to stop this thread.
virtual void step ()
virtual bool initialize ()
virtual void finalize ()

Protected Attributes

int threadnb
 Threads are given an unique number, which follows thread creation order.

Friends

void * periodicThread (void *t)

Detailed Description

A PeriodicThread executes its step() method (or a RunnableInterface ) periodically.

It has a fixed priority, a name and a (changable) periodicity. The common methods to use are start() and stop().

Step() Overruns are detected and the threshold to 'emergency stop' the thread can be set by setMaxOverrun(). Overruns must be accumulated 'on average' to trigger this behavior: one not overrunning step() compensates for one overrunning step().

Definition at line 65 of file PeriodicThread.hpp.


Constructor & Destructor Documentation

RTT::OS::PeriodicThread::PeriodicThread ( int  priority,
const std::string &  name,
double  period,
OS::RunnableInterface r = 0 
)

Create a Thread with a given priority and a name.

Parameters:
priority The priority of the thread, with zero being the highest, 99 being the lowest.
name The name of the Thread.
period The period in seconds (eg 0.001) of the thread.
r The optional RunnableInterface instance to run. If not present, the thread's own virtual functions are executed.
RTT::OS::PeriodicThread::PeriodicThread ( int  scheduler,
int  priority,
const std::string &  name,
double  period,
OS::RunnableInterface r = 0 
)

Create a Thread with a given scheduler type, priority and a name.

Parameters:
scheduler The scheduler, one of ORO_SCHED_RT or ORO_SCHED_OTHER.
priority The priority of the thread, with zero being the highest, 99 being the lowest.
name The name of the Thread.
period The period in seconds (eg 0.001) of the thread.
r The optional RunnableInterface instance to run. If not present, the thread's own virtual functions are executed.

Member Function Documentation

virtual Seconds RTT::OS::PeriodicThread::getPeriod (  )  const [virtual]

Get the periodicity in Seconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

virtual nsecs RTT::OS::PeriodicThread::getPeriodNS (  )  const [virtual]

Get the periodicity in nanoseconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

virtual int RTT::OS::PeriodicThread::getPriority (  )  const [virtual]

The priority of this Thread.

Returns:
The priority given upon construction of this thread or set with setPriority. The returned number has to be interpreted in the current OS scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual int RTT::OS::PeriodicThread::getScheduler (  )  const [virtual]

Get the scheduler policy in which this thread runs.

Returns:
An OS-specific value which represents the used scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual RTOS_TASK* RTT::OS::PeriodicThread::getTask (  )  [inline, virtual]

Get the RTOS_TASK pointer.

Note:
Using this function leads to non-portable code. It is here for users which wish to tweak OS specific thread settings.

Implements RTT::OS::ThreadInterface.

Definition at line 119 of file PeriodicThread.hpp.

virtual bool RTT::OS::PeriodicThread::isActive (  )  const [virtual]

Returns whether the thread is active.

A thread is active between the invocation of start() and the invocation of stop().

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::isRunning (  )  const [virtual]

Returns whether the thread is running.

A thread is running if it is executing its loop() function or in the process of periodically calling step(). Hence for periodic threads, isRunning() == isActive() while for non-periodic threads, isRunning() is only true if isActive() and it is executing loop().

Implements RTT::OS::ThreadInterface.

Reimplemented in RTT::SimulationThread.

virtual bool RTT::OS::PeriodicThread::run ( OS::RunnableInterface r  )  [virtual]

Run the functionality of one RunnableInterface object.

Only one RunnableInterface object can be run, the old one is disconnected.

Parameters:
r The object to run or zero to clear.
Returns:
true if accepted, false if the thread is running.

Implements RTT::OS::ThreadInterface.

bool RTT::OS::PeriodicThread::setPeriod ( Seconds  new_period  )  [virtual]

Set the periodicity in Seconds.

Parameters:
new_period A positive number expressing the period
Returns:
true if it was accepted, false otherwise.

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::setPriority ( int  priority  )  [virtual]

Set the priority of this Thread.

Parameters:
priority The priority given upon construction of this thread. It has to be interpreted in the current OS scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::setScheduler ( int  sched_type  )  [virtual]

Change the scheduler policy in which this thread runs.

Parameters:
sched_type An OS-specific value which selects a scheduler. Orocos requires that these two values are available:

  • ORO_SCHED_RT: Hint the OS that this thread should be scheduled as a priority or real-time process.
  • ORO_SCHED_OTHER: Hint the OS that this thread should not be scheduled as a priority or real-time process.

Your OS can in addition provide other sched_type's which map more naturally to the schedulers present. If your OS does not make a distinction between real-time and other, both values may map to the same scheduler type.

Returns:
true if the change could be made.

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::setToStop (  )  [protected, virtual]

Use this from within step() to stop this thread.

This function will call finalize() as well, thus it is advised to call this function as the last statement in your step().

virtual bool RTT::OS::PeriodicThread::start (  )  [virtual]

Start the Thread.

Postcondition:
initialize() is called first
The Thread is running
Returns:
true if the function did succeed. false otherwise.

Implements RTT::OS::ThreadInterface.

Reimplemented in RTT::SimulationThread.

virtual bool RTT::OS::PeriodicThread::stop (  )  [virtual]

Stop the Thread.

Postcondition:
The Thread is no longer being run
finalize() is called when the Thread is stopped.
Returns:
true if the function did succeed. false otherwise.

Implements RTT::OS::ThreadInterface.

void RTT::OS::PeriodicThread::terminate (  ) 

Exit and destroy the thread.

Precondition:
this is only called from within the destructor.
Postcondition:
the thread does no longer exist.

Member Data Documentation

int RTT::OS::ThreadInterface::threadnb [protected, inherited]

Threads are given an unique number, which follows thread creation order.

See also:
OS::threads

Definition at line 191 of file ThreadInterface.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Dec 23 13:22:47 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3