Orocos Real-Time Toolkit  2.6.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes
RTT::extras::SimulationThread Class Reference

This thread is the simulated real-time periodic thread in the Orocos system. More...

#include <rtt/extras/SimulationThread.hpp>

Inheritance diagram for RTT::extras::SimulationThread:
RTT::extras::TimerThread RTT::os::Thread RTT::os::ThreadInterface

List of all members.

Public Member Functions

virtual ~SimulationThread ()
 Destructor.
virtual bool start ()
 Start the Thread.
virtual bool isRunning () const
 Returns true if thread is running or run( unsigned int ) is being invoked.
virtual bool start (unsigned int maxsteps)
 Only run the simulation maxsteps time steps, then stop the SimulationThread.
virtual bool run (unsigned int maxsteps)
 Execute maxsteps steps immediately.
virtual os::ThreadInterfacesimthread ()
 Always returns the MainThread.
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 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 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 unsigned int getPid () const
 Returns the Process or Thread ID of this thread, as assigned by the Operating System.
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 SimulationThreadPtr Instance (double period=0.001)
 Create the SimulationThread with a given period.
static bool Release ()
 Releases the SimulationThread Reference counting might aid in making this call safe.
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

bool initialize ()
void step ()
void finalize ()
 SimulationThread (double period)
 Constructor.
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.

Detailed Description

This thread is the simulated real-time periodic thread in the Orocos system.

All your activities in the same program must be a SimulationActivity for this to work, since the os::TimeService global time is updated when this thread runs.

By default, the update period is 0.001 seconds. If you want to run with a finer or coarser grained time step, use the Instance() method and supply another period before SimulationActivities are created.

Note:
This implementation has lost the capability to run SimulationActivity objects of different periods.

Definition at line 64 of file SimulationThread.hpp.


Member Function Documentation

bool RTT::os::Thread::breakLoop ( ) [protected, virtual, inherited]
void RTT::SimulationThread::finalize ( ) [protected, virtual]
unsigned RTT::os::Thread::getCpuAffinity ( ) const [virtual, inherited]
Returns:
the cpu affinity (
See also:
rtos_task_set_cpu_affinity)

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 run(), 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.

unsigned int RTT::os::Thread::getPid ( ) const [virtual, inherited]

Returns the Process or Thread ID of this thread, as assigned by the Operating System.

This function tries to return the Thread ID, if the OS supports it, otherwise it returns the process ID. If that is not available either, zero is returned. On Linux systems for example, the Thread ID of the main thread is equal to the Process ID. The Thread ID of every newly created thread is different from the Process ID (and unique).

Implements RTT::os::ThreadInterface.

Definition at line 598 of file Thread.cpp.

References RTT::os::rtos_task_get_pid().

int RTT::os::Thread::getPriority ( ) const [virtual, inherited]

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.

Definition at line 573 of file Thread.cpp.

References RTT::os::rtos_task_get_priority().

Referenced by SimulationThread().

int RTT::os::Thread::getScheduler ( ) const [virtual, inherited]

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.

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.

Note:
Using this function leads to non-portable code. It is here for users which wish to tweak OS specific thread settings.

Implements RTT::os::ThreadInterface.

Definition at line 174 of file Thread.hpp.

Referenced by RTT::os::thread_function().

bool RTT::SimulationThread::initialize ( ) [protected, virtual]
SimulationThreadPtr RTT::SimulationThread::Instance ( double  period = 0.001) [static]

Create the SimulationThread with a given period.

Only one SimulationThread can be created.

Parameters:
periodThe period in seconds at which the simulation takes steps and updates the TimeService. Only the first invocation of Instance will consider this parameter. The others will ignore it.

Definition at line 69 of file SimulationThread.cpp.

Referenced by simthread(), and RTT::extras::SimulationActivity::thread().

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().

void RTT::os::Thread::loop ( ) [protected, virtual, inherited]
bool RTT::SimulationThread::Release ( ) [static]

Releases the SimulationThread Reference counting might aid in making this call safe.

Returns:
true on success, false on failure

Definition at line 79 of file SimulationThread.cpp.

bool RTT::SimulationThread::run ( unsigned int  maxsteps) [virtual]

Execute maxsteps steps immediately.

This function will call the step() functions maxsteps times, without requiring start() or stop() to be called before or after. The thread is thus not used.

Returns:
false if maxsteps == 0
Postcondition:
When run() returns, step() has been called maxsteps times.

Definition at line 122 of file SimulationThread.cpp.

References finalize(), RTT::os::Thread::getPeriod(), initialize(), isRunning(), RTT::os::TimeService::secondsChange(), and step().

bool RTT::os::Thread::setCpuAffinity ( unsigned  cpu_affinity) [virtual, inherited]

Set cpu affinity for this thread The cpu affinity of the thread (.

See also:
rtos_task_set_cpu_affinity).
Returns:
true if the mask has been applied

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.

Parameters:
new_periodA positive number expressing the period
Returns:
true if it was accepted, false otherwise.

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.

Parameters:
priorityThe priority given upon construction of this thread. It has to be interpreted in the current OS scheduler.
See also:
setScheduler

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.

Parameters:
sched_typeAn 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.

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

Parameters:
ssizethe 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.

Parameters:
Thewait policy between ORO_WAIT_ABS (absolute wait) and ORO_WAIT_REL (relative wait)

Implements RTT::os::ThreadInterface.

Definition at line 634 of file Thread.cpp.

References RTT::os::rtos_task_set_wait_period_policy().

bool RTT::SimulationThread::start ( ) [virtual]

Start the Thread.

Postcondition:
initialize() is called first
The Thread is running
Returns:
true if the function did succeed. false otherwise.

Reimplemented from RTT::os::Thread.

Definition at line 108 of file SimulationThread.cpp.

Referenced by start().

bool RTT::SimulationThread::start ( unsigned int  maxsteps) [virtual]

Only run the simulation maxsteps time steps, then stop the SimulationThread.

Returns:
false if maxsteps == 0 or if thread could not be started.

Definition at line 114 of file SimulationThread.cpp.

References start().

void RTT::SimulationThread::step ( ) [protected, virtual]
bool RTT::os::Thread::stop ( ) [virtual, inherited]

Stop the Thread.

Postcondition:
The Thread is no longer being run
finalize() is called when the Thread is stopped.
Returns:
true if the function did succeed. false otherwise.

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 step(), ~SimulationThread(), and RTT::extras::TimerThread::~TimerThread().

void RTT::os::Thread::terminate ( ) [protected, inherited]

Exit and destroy the thread.

Precondition:
this is only called from within the destructor.
Postcondition:
the thread does no longer exist.

Definition at line 608 of file Thread.cpp.

References RTT::os::rtos_task_delete().


Member Data Documentation

os::MutexRecursive RTT::extras::TimerThread::mutex [mutable, protected, inherited]

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 RTT::extras::TimerThread::addActivity(), RTT::extras::TimerThread::finalize(), and RTT::extras::TimerThread::step().

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 223 of file ThreadInterface.hpp.


The documentation for this class was generated from the following files: