SingleThread Class Reference

#include </home/sspr/src/www/orocos-1.0/export/build/orocos-rtt-1.2.2/build/rtt/os/SingleThread.hpp>

Inheritance diagram for SingleThread:

ThreadInterface NonPeriodicActivity CompletionProcessor List of all members.

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. When stop() is called when 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(). A next invocation of start() will again call initialize() before loop() is executed and so on. The user must provide an implementation of breakLoop() returning true to make stop() work while loop() is being executed. stop() will not execute finalize() if the thread executes loop() and breakLoop() is not reimplemented to return true. If the thread was not executing loop(), stop will always call finalize() and return success.

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


Public Types

typedef double Seconds
typedef long secs
typedef long msecs
typedef long long nsecs

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 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 (but to the back of the scheduler queue) the calling thread.
unsigned int threadNumber () const
 The unique thread number.

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)


Constructor & Destructor Documentation

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.

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 bool 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 ThreadInterface.

virtual bool 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 ThreadInterface.

Reimplemented in NonPeriodicActivity.

virtual bool 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 ThreadInterface.

Reimplemented in NonPeriodicActivity.

virtual bool 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 ThreadInterface.

virtual int 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 ThreadInterface.

virtual Seconds getPeriod (  )  const [inline, virtual]

Get the periodicity in Seconds.

Return zero if non periodic.

Implements ThreadInterface.

Reimplemented in NonPeriodicActivity.

virtual nsecs getPeriodNS (  )  const [inline, virtual]

Get the periodicity in nanoseconds.

Return zero if non periodic.

Implements ThreadInterface.

virtual bool 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 ThreadInterface.

virtual int 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 ThreadInterface.


Member Data Documentation

int threadnb [protected, inherited]

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

See also:
OS::threads


The documentation for this class was generated from the following file:
Generated on Fri Oct 19 16:27:29 2007 for Orocos by  doxygen 1.5.1