Orocos Real-Time Toolkit
2.5.0
|
This Periodic Thread is meant for executing a PeriodicActivity object periodically. More...
#include <rtt/extras/TimerThread.hpp>
Public Member Functions | |
TimerThread (int priority, const std::string &name, double periodicity, unsigned cpu_affinity=~0) | |
Create a periodic Timer thread. | |
TimerThread (int scheduler, int priority, const std::string &name, double periodicity, unsigned cpu_affinity=~0) | |
Create a periodic Timer thread with a given scheduler type. | |
virtual | ~TimerThread () |
Destructor. | |
bool | addActivity (PeriodicActivity *t) |
Add an Timer that will be ticked every execution period Once added, a timer can not be removed. | |
bool | removeActivity (PeriodicActivity *t) |
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) |
Set the periodicity of this thread (seconds, nanoseconds) | |
bool | setPeriod (TIME_SPEC p) |
Set the periodicity of this thread. | |
void | getPeriod (secs &s, nsecs &ns) const |
Get the periodicity of this thread (seconds, nanoseconds) | |
virtual Seconds | getPeriod () const |
Get the periodicity in Seconds. | |
virtual nsecs | getPeriodNS () const |
Get the periodicity in nanoseconds. | |
virtual bool | isPeriodic () const |
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 const RTOS_TASK * | getTask () const |
const version of the above. | |
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 bool | setPriority (int priority) |
Set the priority of this Thread. | |
virtual int | getPriority () const |
The priority of this Thread. | |
virtual bool | setCpuAffinity (unsigned cpu_affinity) |
Set cpu affinity for this thread The cpu affinity of the thread (. | |
virtual unsigned | getCpuAffinity () const |
virtual void | yield () |
Yields (put to the back of the scheduler queue) the calling thread. | |
virtual void | setMaxOverrun (int m) |
virtual int | getMaxOverrun () const |
virtual void | setWaitPeriodPolicy (int p) |
Set the wait policy of a periodic thread. | |
unsigned int | threadNumber () const |
The unique thread number (within the same process). | |
bool | isSelf () const |
Static Public Member Functions | |
static TimerThreadPtr | Instance (int priority, double periodicity) |
Create a TimerThread with a given priority and periodicity, using the default scheduler, ORO_SCHED_RT. | |
static TimerThreadPtr | Instance (int scheduler, int priority, double periodicity) |
Create a TimerThread with a given scheduler, priority and periodicity. | |
static TimerThreadPtr | Instance (int scheduler, int priority, double periodicity, unsigned cpu_affinity) |
Create a TimerThread with a given scheduler, priority and periodicity. | |
static void | setStackSize (unsigned int ssize) |
Sets the stack size of the threads to be created. | |
Static Public Attributes | |
static const unsigned int | MAX_ACTIVITIES = 64 |
Protected Types | |
typedef std::vector < boost::weak_ptr< TimerThread > > | TimerThreadList |
A Boost weak pointer is used to store non-owning pointers to shared objects. | |
Protected Member Functions | |
virtual bool | initialize () |
virtual void | step () |
virtual void | finalize () |
void | reorderList () |
void | terminate () |
Exit and destroy the thread. | |
void | emergencyStop () |
virtual void | loop () |
virtual bool | breakLoop () |
Protected Attributes | |
os::MutexRecursive | mutex |
A Activity can not create a activity of same priority from step(). | |
int | threadnb |
Threads are given an unique number, which follows thread creation order. | |
Static Protected Attributes | |
static TimerThreadList | TimerThreads |
All timer threads. |
This Periodic Thread is meant for executing a PeriodicActivity object periodically.
Definition at line 69 of file TimerThread.hpp.
RTT::TimerThread::TimerThread | ( | int | priority, |
const std::string & | name, | ||
double | periodicity, | ||
unsigned | cpu_affinity = ~0 |
||
) |
Create a periodic Timer thread.
priority | The priority of this thread |
periodicity | The periodicity of this thread in seconds (e.g. 0.001 = 1000Hz ) |
Definition at line 90 of file TimerThread.cpp.
RTT::TimerThread::TimerThread | ( | int | scheduler, |
int | priority, | ||
const std::string & | name, | ||
double | periodicity, | ||
unsigned | cpu_affinity = ~0 |
||
) |
Create a periodic Timer thread with a given scheduler type.
scheduler | The scheduler in which this thread runs |
priority | The priority of this thread within scheduler |
periodicity | The periodicity of this thread in seconds (e.g. 0.001 = 1000Hz ) |
Definition at line 96 of file TimerThread.cpp.
bool RTT::os::Thread::breakLoop | ( | ) | [protected, virtual, inherited] |
Reimplemented in RTT::corba::OrbRunner, RTT::extras::FileDescriptorActivity, RTT::mqueue::Dispatcher, RTT::Activity, and RTT::corba::CorbaDispatcher.
Definition at line 508 of file Thread.cpp.
Referenced by RTT::os::Thread::stop().
void RTT::TimerThread::finalize | ( | ) | [protected, virtual] |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::extras::SimulationThread.
Definition at line 135 of file TimerThread.cpp.
References mutex.
unsigned RTT::os::Thread::getCpuAffinity | ( | ) | const [virtual, inherited] |
Reimplemented in RTT::Activity.
Definition at line 593 of file Thread.cpp.
References RTT::os::rtos_task_get_cpu_affinity().
double RTT::os::Thread::getPeriod | ( | ) | const [virtual, inherited] |
Get the periodicity in Seconds.
Return zero if non periodic.
Implements RTT::os::ThreadInterface.
Reimplemented in RTT::Activity.
Definition at line 578 of file Thread.cpp.
Referenced by RTT::extras::SimulationThread::run(), RTT::extras::SimulationThread::SimulationThread(), RTT::extras::SimulationThread::step(), and RTT::os::Thread::stop().
nsecs RTT::os::Thread::getPeriodNS | ( | ) | const [virtual, inherited] |
Get the periodicity in nanoseconds.
Return zero if non periodic.
Implements RTT::os::ThreadInterface.
Definition at line 583 of file Thread.cpp.
int RTT::os::Thread::getPriority | ( | ) | const [virtual, inherited] |
The priority of this Thread.
Implements RTT::os::ThreadInterface.
Definition at line 573 of file Thread.cpp.
References RTT::os::rtos_task_get_priority().
Referenced by RTT::extras::SimulationThread::SimulationThread().
int RTT::os::Thread::getScheduler | ( | ) | const [virtual, inherited] |
Get the scheduler policy in which this thread runs.
Implements RTT::os::ThreadInterface.
Definition at line 475 of file Thread.cpp.
References RTT::os::rtos_task_get_scheduler().
Referenced by RTT::os::Thread::setScheduler().
virtual RTOS_TASK* RTT::os::Thread::getTask | ( | ) | [inline, virtual, inherited] |
Get the RTOS_TASK pointer.
Implements RTT::os::ThreadInterface.
Definition at line 174 of file Thread.hpp.
Referenced by RTT::os::thread_function().
bool RTT::TimerThread::initialize | ( | ) | [protected, virtual] |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::extras::SimulationThread.
Definition at line 131 of file TimerThread.cpp.
bool RTT::os::Thread::isActive | ( | ) | const [virtual, inherited] |
Returns whether the thread is active.
A thread is active between the invocation of start() and the invocation of stop().
Implements RTT::os::ThreadInterface.
Reimplemented in RTT::Activity.
Definition at line 451 of file Thread.cpp.
Referenced by RTT::os::Thread::start().
bool RTT::os::Thread::isRunning | ( | ) | const [virtual, inherited] |
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::Activity, RTT::extras::FileDescriptorActivity, and RTT::extras::SimulationThread.
Definition at line 446 of file Thread.cpp.
void RTT::os::Thread::loop | ( | ) | [protected, virtual, inherited] |
Reimplemented in RTT::corba::OrbRunner, RTT::extras::FileDescriptorActivity, RTT::Activity, RTT::mqueue::Dispatcher, and RTT::corba::CorbaDispatcher.
Definition at line 503 of file Thread.cpp.
References RTT::os::Thread::step().
Referenced by RTT::os::thread_function().
bool RTT::os::Thread::setCpuAffinity | ( | unsigned | cpu_affinity | ) | [virtual, inherited] |
Set cpu affinity for this thread The cpu affinity of the thread (.
Reimplemented in RTT::Activity.
Definition at line 588 of file Thread.cpp.
References RTT::os::rtos_task_set_cpu_affinity().
bool RTT::os::Thread::setPeriod | ( | Seconds | new_period | ) | [virtual, inherited] |
Set the periodicity in Seconds.
new_period | A positive number expressing the period |
Implements RTT::os::ThreadInterface.
Reimplemented in RTT::Activity.
Definition at line 523 of file Thread.cpp.
Referenced by RTT::os::Thread::setPeriod().
bool RTT::os::Thread::setPriority | ( | int | priority | ) | [virtual, inherited] |
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.
Definition at line 563 of file Thread.cpp.
References RTT::os::rtos_task_set_priority().
bool RTT::os::Thread::setScheduler | ( | int | sched_type | ) | [virtual, inherited] |
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.
Definition at line 456 of file Thread.cpp.
References RTT::os::CheckScheduler(), RTT::os::Thread::getScheduler(), RTT::os::rtos_task_get_name(), and RTT::os::rtos_task_set_scheduler().
Referenced by RTT::extras::SimulationThread::SimulationThread().
void RTT::os::Thread::setStackSize | ( | unsigned int | ssize | ) | [static, inherited] |
Sets the stack size of the threads to be created.
This value is suggestive and may be altered or ignored by your operating system. Use zero to use the system's default.
ssize | the size of the stack in bytes |
Definition at line 73 of file Thread.cpp.
void RTT::os::Thread::setWaitPeriodPolicy | ( | int | p | ) | [virtual, inherited] |
Set the wait policy of a periodic thread.
The | wait policy between ORO_WAIT_ABS (absolute wait) and ORO_WAIT_REL (relative wait) |
Implements RTT::os::ThreadInterface.
Definition at line 629 of file Thread.cpp.
References RTT::os::rtos_task_set_wait_period_policy().
bool RTT::os::Thread::start | ( | ) | [virtual, inherited] |
Start the Thread.
Implements RTT::os::ThreadInterface.
Reimplemented in RTT::extras::FileDescriptorActivity, RTT::Activity, RTT::extras::IRQActivity, and RTT::extras::SimulationThread.
Definition at line 339 of file Thread.cpp.
References RTT::os::Thread::initialize(), RTT::os::Thread::isActive(), and RTT::os::rtos_task_make_periodic().
void RTT::TimerThread::step | ( | ) | [protected, virtual] |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::extras::SimulationThread.
Definition at line 145 of file TimerThread.cpp.
References mutex.
bool RTT::os::Thread::stop | ( | ) | [virtual, inherited] |
Stop the Thread.
Implements RTT::os::ThreadInterface.
Reimplemented in RTT::extras::FileDescriptorActivity, and RTT::Activity.
Definition at line 404 of file Thread.cpp.
References RTT::os::Thread::breakLoop(), RTT::os::Thread::finalize(), RTT::os::Thread::getName(), RTT::os::Thread::getPeriod(), RTT::os::MutexTimedLock::isSuccessful(), and RTT::os::rtos_task_make_periodic().
Referenced by RTT::extras::SimulationThread::step(), RTT::extras::SimulationThread::~SimulationThread(), and ~TimerThread().
void RTT::os::Thread::terminate | ( | ) | [protected, inherited] |
Exit and destroy the thread.
Definition at line 603 of file Thread.cpp.
References RTT::os::rtos_task_delete().
os::MutexRecursive RTT::extras::TimerThread::mutex [mutable, protected] |
A Activity can not create a activity of same priority from step().
If so a deadlock will occur.
Definition at line 134 of file TimerThread.hpp.
Referenced by addActivity(), finalize(), and step().
int RTT::os::ThreadInterface::threadnb [protected, inherited] |
Threads are given an unique number, which follows thread creation order.
Definition at line 211 of file ThreadInterface.hpp.