RTT::OS::SingleThread Class Reference

This Thread abstraction class represents a single-shot thread which can be started many times. More...

#include <rtt/os/SingleThread.hpp>

Inheritance diagram for RTT::OS::SingleThread:
RTT::OS::ThreadInterface RTT::NonPeriodicActivity RTT::CompletionProcessor RTT::EventDrivenActivity

List of all members.

Public Member Functions

 SingleThread (int priority, const std::string &name, OS::RunnableInterface *r=0)
 Create a single-shot Thread with priority priority, a name and optionally, an object to execute.
 SingleThread (int scheduler, int priority, const std::string &name, OS::RunnableInterface *r=0)
 Create a single-shot Thread with priority priority, a name and optionally, an object to execute.
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.
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 FIXME should this be a const?
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.
virtual Seconds getPeriod () const
 Get the periodicity in Seconds.
virtual bool setPeriod (Seconds period)
 Set the periodicity in Seconds.
virtual nsecs getPeriodNS () const
 Get the periodicity in nanoseconds.
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.
unsigned int threadNumber () const
 The unique thread number (within the same process).

Protected Member Functions

virtual bool breakLoop ()
virtual void loop ()
virtual bool initialize ()
virtual void finalize ()

Protected Attributes

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

Friends

void * singleThread_f (void *t)

Detailed Description

This Thread abstraction class represents a single-shot thread which can be started many times.

The first invocation of start() invokes the initialize() function and runs the loop() method in the thread. When loop() returns the thread waits for another start() to execute loop() again. In that case, initialize() is not executed.

When stop() is called and the thread is still executing loop() and breakLoop() returns true (not the default), the stop() function succeeds and the finalize() method is called by stop(). If the thread was not executing loop(), stop will always call finalize() and return success.

The user must provide an implementation of breakLoop() returning true to make stop() work while loop() is being executed. stop() will fail and not execute finalize() if the thread executes loop() and breakLoop() is not reimplemented to return true.

When a RunnableInterface object is given, the above methods initialize(), loop(), breakLoop() and finalize() are called on that object instead of on the SingleThread's virtual functions.

See also:
RunnableInterface

Definition at line 84 of file SingleThread.hpp.


Constructor & Destructor Documentation

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

Create a single-shot Thread with priority priority, a name and optionally, an object to execute.

Parameters:
priority The priority of the thread, in the ORO_SCHED_RT domain.
name The name of the Thread.
r The optional RunnableInterface instance to run. If not present, the thread's own virtual functions are executed.
RTT::OS::SingleThread::SingleThread ( int  scheduler,
int  priority,
const std::string &  name,
OS::RunnableInterface r = 0 
)

Create a single-shot Thread with priority priority, a name and optionally, an object to execute.

Parameters:
scheduler The scheduler, one of ORO_SCHED_RT or ORO_SCHED_OTHER.
priority The priority of the thread, in the scheduler domain.
name The name 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::SingleThread::getPeriod (  )  const [inline, virtual]

Get the periodicity in Seconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

Reimplemented in RTT::NonPeriodicActivity.

Definition at line 162 of file SingleThread.hpp.

virtual nsecs RTT::OS::SingleThread::getPeriodNS (  )  const [inline, virtual]

Get the periodicity in nanoseconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

Definition at line 164 of file SingleThread.hpp.

virtual int RTT::OS::SingleThread::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::SingleThread::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 bool RTT::OS::SingleThread::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.

virtual bool RTT::OS::SingleThread::setPeriod ( Seconds  new_period  )  [inline, 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.

Definition at line 163 of file SingleThread.hpp.

virtual bool RTT::OS::SingleThread::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::SingleThread::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::SingleThread::start (  )  [virtual]

Start the thread.

Postcondition:
if !this->isRunning(), then execute initialize() and execute loop() in the thread.
if this->isRunning(), then schedule a start of loop() in the thread.
this->isRunning is true
Returns:
true if successfull.

Implements RTT::OS::ThreadInterface.

Reimplemented in RTT::EventDrivenActivity, and RTT::NonPeriodicActivity.

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

Stop the thread.

The return value of stop, is the same as the return value of RunnableInterface::breakLoop().

Precondition:
this->isRunning()
Postcondition:
if breakLoop() returns true, then execute finalize() and this->isRunning() == false
if breakLoop() returns false (the default), then do nothing.
Returns:
true if successfull.

Implements RTT::OS::ThreadInterface.

Reimplemented in RTT::EventDrivenActivity, and RTT::NonPeriodicActivity.


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