This Thread abstraction class represents a single-shot thread which can be started many times. More...
#include <rtt/os/SingleThread.hpp>
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) |
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.
Definition at line 84 of file SingleThread.hpp.
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.
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.
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. |
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.
Implements RTT::OS::ThreadInterface.
virtual int RTT::OS::SingleThread::getScheduler | ( | ) | const [virtual] |
Get the scheduler policy in which this thread runs.
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.
r | The object to run or zero to clear. |
Implements RTT::OS::ThreadInterface.
virtual bool RTT::OS::SingleThread::setPeriod | ( | Seconds | new_period | ) | [inline, virtual] |
Set the periodicity in Seconds.
new_period | A positive number expressing the period |
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.
priority | The priority given upon construction of this thread. It has to be interpreted in the current OS scheduler. |
Implements RTT::OS::ThreadInterface.
virtual bool RTT::OS::SingleThread::setScheduler | ( | int | sched_type | ) | [virtual] |
Change the scheduler policy in which this thread runs.
sched_type | An OS-specific value which selects a scheduler. Orocos requires that these two values are available: |
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.
Implements RTT::OS::ThreadInterface.
virtual bool RTT::OS::SingleThread::start | ( | ) | [virtual] |
Start the thread.
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().
Implements RTT::OS::ThreadInterface.
Reimplemented in RTT::EventDrivenActivity, and RTT::NonPeriodicActivity.
int RTT::OS::ThreadInterface::threadnb [protected, inherited] |
Threads are given an unique number, which follows thread creation order.
Definition at line 191 of file ThreadInterface.hpp.