#include <rtt/os/SingleThread.hpp>

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.
Definition at line 80 of file SingleThread.hpp.
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 | ~SingleThread () |
| 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) |
| 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. |
Definition at line 137 of file SingleThread.cpp.
| 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. |
Definition at line 150 of file SingleThread.cpp.
| 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.
| r | The object to run or zero to clear. |
Implements ThreadInterface.
Reimplemented in NonPeriodicActivity.
Definition at line 266 of file SingleThread.cpp.
References SingleThread::isActive(), and RunnableInterface::setThread().
| bool start | ( | ) | [virtual] |
Start the thread.
if this->isRunning(), then schedule a start of loop() in the thread.
this->isRunning is true
Implements ThreadInterface.
Reimplemented in NonPeriodicActivity.
Definition at line 278 of file SingleThread.cpp.
References SingleThread::isActive().
Referenced by NonPeriodicActivity::start(), and NonPeriodicActivity::trigger().
| bool stop | ( | ) | [virtual] |
Stop the thread.
The return value of stop, is the same as the return value of RunnableInterface::breakLoop().
if breakLoop() returns false (the default), then do nothing.
Implements ThreadInterface.
Reimplemented in NonPeriodicActivity.
Definition at line 304 of file SingleThread.cpp.
References SingleThread::finalize(), and SingleThread::isActive().
Referenced by NonPeriodicActivity::stop(), and SingleThread::~SingleThread().
| bool 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: |
Implements ThreadInterface.
Definition at line 242 of file SingleThread.cpp.
References RTT::Warning.
| int getScheduler | ( | ) | const [virtual] |
Get the scheduler policy in which this thread runs.
Implements ThreadInterface.
Definition at line 261 of file SingleThread.cpp.
| virtual Seconds getPeriod | ( | ) | const [inline, virtual] |
Get the periodicity in Seconds.
Return zero if non periodic.
Implements ThreadInterface.
Reimplemented in NonPeriodicActivity.
Definition at line 158 of file SingleThread.hpp.
| virtual nsecs getPeriodNS | ( | ) | const [inline, virtual] |
Get the periodicity in nanoseconds.
Return zero if non periodic.
Implements ThreadInterface.
Definition at line 159 of file SingleThread.hpp.
| bool 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 ThreadInterface.
Definition at line 370 of file SingleThread.cpp.
| int getPriority | ( | ) | const [virtual] |
The priority of this Thread.
Implements ThreadInterface.
Definition at line 375 of file SingleThread.cpp.
| void* singleThread_f | ( | void * | t | ) | [friend] |
This is one time initialisation
The real task starts here.
Definition at line 57 of file SingleThread.cpp.
int threadnb [protected, inherited] |
Threads are given an unique number, which follows thread creation order.
Definition at line 182 of file ThreadInterface.hpp.
Referenced by ThreadInterface::ThreadInterface(), and ThreadInterface::threadNumber().
1.5.3