Orocos Real-Time Toolkit  2.8.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RTT::internal::GlobalEngine Class Reference

A process-wide execution engine that processes every asynchronous operation that is not being processed by a TaskContext. More...

#include <rtt/internal/GlobalEngine.hpp>

Inheritance diagram for RTT::internal::GlobalEngine:
RTT::ExecutionEngine RTT::base::RunnableInterface

Public Member Functions

base::TaskCoregetParent ()
 The base::TaskCore which created this ExecutionEngine. More...
 
virtual void addChild (base::TaskCore *tc)
 Add a base::TaskCore to execute. More...
 
virtual void removeChild (base::TaskCore *tc)
 Remove a base::TaskCore from execution. More...
 
base::TaskCoregetTaskCore () const
 Returns the owner of this execution engine. More...
 
virtual bool process (base::DisposableInterface *c)
 Queue and execute (process) a given message. More...
 
virtual bool runFunction (base::ExecutableInterface *f)
 Run a given function in step() or loop(). More...
 
virtual bool removeFunction (base::ExecutableInterface *f)
 Remove a running function added with runFunction. More...
 
virtual bool removeSelfFunction (base::ExecutableInterface *f)
 Self-removal for a running function added with runFunction. More...
 
void waitForMessages (const boost::function< bool(void)> &pred)
 Call this if you wish to block on a message arriving in the Execution Engine. More...
 
void waitForFunctions (const boost::function< bool(void)> &pred)
 Call this if you wish to block on a function completing in the Execution Engine. More...
 
bool stopTask (base::TaskCore *task)
 Stops executing the updateHook of task. More...
 
void setExceptionTask ()
 Set the 'owner' task in the exception state. More...
 
void setMaster (ExecutionEngine *master)
 Set the master ExecutionEngine. More...
 
virtual void setActivity (base::ActivityInterface *task)
 Overwritten version of RTT::base::RunnableInterface::setActivity(). More...
 
virtual void loop ()
 The method that will be executed once when this class is run in a non periodic thread. More...
 
virtual os::ThreadInterfacegetThread () const
 Get the thread this object is run in. More...
 
ActivityInterfacegetActivity () const
 Query for the task this interface is run in. More...
 

Static Public Member Functions

static RTT_API ExecutionEngineInstance ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This is kept (instead of using default parameters) for ABI compatibility. More...
 
static RTT_API ExecutionEngineInstance (int scheduler, int priority=os::LowestPriority, unsigned cpu_affinity=0)
 
static RTT_API void Release ()
 

Protected Member Functions

void waitForMessagesInternal (boost::function< bool(void)> const &pred)
 Call this if you wish to block on a message arriving in the Execution Engine. More...
 
void waitAndProcessMessages (boost::function< bool(void)> const &pred)
 Call this if you wish to block on a message arriving in the Execution Engine and execute it. More...
 
void waitAndProcessFunctions (boost::function< bool(void)> const &pred)
 Call this if you wish to block on a function completing in the Execution Engine and execute it. More...
 
void processMessages ()
 
void processFunctions ()
 
void processChildren ()
 
virtual bool initialize ()
 The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started. More...
 
virtual void step ()
 Executes (in that order) Messages, Functions and updateHook() functions of this TaskContext and its children. More...
 
virtual bool breakLoop ()
 This method is called by the framework to break out of the loop() method. More...
 
virtual void finalize ()
 The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped. More...
 
virtual bool hasWork ()
 This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again). More...
 

Protected Attributes

base::TaskCoretaskc
 The parent or 'owner' of this ExecutionEngine, may be null. More...
 
internal::MWSRQueue< base::DisposableInterface * > * mqueue
 Our Message queue. More...
 
std::vector< base::TaskCore * > children
 
internal::MWSRQueue< base::ExecutableInterface * > * f_queue
 Stores all functions we're executing. More...
 
os::Mutex msg_lock
 
os::Condition msg_cond
 
ExecutionEnginemmaster
 A master ExecutionEngine which should process our messages. More...
 

Detailed Description

A process-wide execution engine that processes every asynchronous operation that is not being processed by a TaskContext.

In practice, this only occurs when a client does a send() on an OperationCaller which calls an Operation with the ClientThread policy.

Definition at line 60 of file GlobalEngine.hpp.

Member Function Documentation

void RTT::ExecutionEngine::addChild ( base::TaskCore tc)
virtualinherited
bool RTT::ExecutionEngine::breakLoop ( )
protectedvirtualinherited

This method is called by the framework to break out of the loop() method.

Reimplement this method to signal loop() to return and return true on success. When this method is not reimplemented by you, it will always return false, denoting that the loop can not be broken. If breakLoop() returns true, the caller will wait until loop() returns.

Returns
true if the loop could be notified to return.

Reimplemented from RTT::base::RunnableInterface.

Definition at line 417 of file ExecutionEngine.cpp.

References RTT::base::TaskCore::breakUpdateHook(), RTT::ExecutionEngine::children, and RTT::ExecutionEngine::taskc.

void RTT::ExecutionEngine::finalize ( )
protectedvirtualinherited

The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped.

Implements RTT::base::RunnableInterface.

Definition at line 453 of file ExecutionEngine.cpp.

ActivityInterface * RTT::base::RunnableInterface::getActivity ( ) const
inlineinherited
TaskCore * RTT::ExecutionEngine::getParent ( )
inherited
base::TaskCore* RTT::ExecutionEngine::getTaskCore ( ) const
inlineinherited

Returns the owner of this execution engine.

Definition at line 109 of file ExecutionEngine.hpp.

os::ThreadInterface * RTT::RunnableInterface::getThread ( ) const
virtualinherited

Get the thread this object is run in.

Returns
a pointer to the thread or 0 if not run by a thread.

Definition at line 78 of file CoreRunnableInterface.cpp.

References RTT::base::ActivityInterface::thread().

bool RTT::ExecutionEngine::hasWork ( )
protectedvirtualinherited

This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again).

By default, false is returned. You should only return true in case there is a temporary reason to (re-)run step.

Returns
true if this object should be run.
See also
extras::SequentialActivity implementation to see how this can be of use.

Reimplemented from RTT::base::RunnableInterface.

Definition at line 212 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::mqueue.

bool RTT::ExecutionEngine::initialize ( )
protectedvirtualinherited

The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started.

Implements RTT::base::RunnableInterface.

Definition at line 207 of file ExecutionEngine.cpp.

static RTT_API ExecutionEngine* RTT::internal::GlobalEngine::Instance ( )
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This is kept (instead of using default parameters) for ABI compatibility.

Definition at line 70 of file GlobalEngine.hpp.

References Instance(), RTT::os::LowestPriority, ORO_SCHED_OTHER, Release(), and RTT_API.

Referenced by RTT::scripting::ScriptingService::evalInternal(), RTT::base::OperationCallerInterface::getMessageProcessor(), Instance(), RTT::scripting::Parser::Parser(), RTT::scripting::FunctionFactory::produce(), and RTT::scripting::ScriptParser::ScriptParser().

ExecutionEngine * RTT::internal::GlobalEngine::Instance ( int  scheduler,
int  priority = os::LowestPriority,
unsigned  cpu_affinity = 0 
)
static

Definition at line 61 of file GlobalEngine.cpp.

void RTT::RunnableInterface::loop ( )
virtualinherited

The method that will be executed once when this class is run in a non periodic thread.

The default implementation calls step() once.

Reimplemented in RTT::os::Timer.

Definition at line 60 of file CoreRunnableInterface.cpp.

References RTT::base::RunnableInterface::step().

Referenced by RTT::extras::SlaveActivity::execute(), and RTT::Activity::loop().

bool RTT::ExecutionEngine::process ( base::DisposableInterface c)
virtualinherited

Queue and execute (process) a given message.

The message is executed in step() or loop() directly after all other queued ActionInterface objects. The constructor parameter queue_size limits how many messages can be queued in between step()s or loop().

Returns
true if the message got accepted, false otherwise.
false when the MessageProcessor is not running or does not accept messages.
See also
acceptMessages

Definition at line 239 of file ExecutionEngine.cpp.

References RTT::os::Condition::broadcast(), RTT::base::TaskCore::FatalError, RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::mmaster, RTT::ExecutionEngine::mqueue, RTT::ExecutionEngine::msg_cond, RTT::base::TaskCore::mTaskState, RTT::ExecutionEngine::process(), RTT::ExecutionEngine::taskc, and RTT::base::ActivityInterface::trigger().

Referenced by RTT::internal::LocalOperationCallerImpl< FunctionT >::do_send(), RTT::internal::LocalOperationCallerImpl< FunctionT >::executeAndDispose(), RTT::internal::FusedMSignal< Signature >::invoke(), RTT::ExecutionEngine::process(), and RTT::ExecutionEngine::removeFunction().

void RTT::ExecutionEngine::processChildren ( )
protectedinherited
void RTT::ExecutionEngine::processFunctions ( )
protectedinherited
void RTT::ExecutionEngine::processMessages ( )
protectedinherited
void RTT::internal::GlobalEngine::Release ( )
static

Definition at line 67 of file GlobalEngine.cpp.

Referenced by __os_exit(), and Instance().

void RTT::ExecutionEngine::removeChild ( base::TaskCore tc)
virtualinherited
bool RTT::ExecutionEngine::removeFunction ( base::ExecutableInterface f)
virtualinherited
bool RTT::ExecutionEngine::removeSelfFunction ( base::ExecutableInterface f)
virtualinherited

Self-removal for a running function added with runFunction.

You must call this variant in case you want yourself to be removed. Equivalent to returning false in ExecutableInterface::execute().

Definition at line 188 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::f_queue.

Referenced by RTT::RemoveMsg::executeAndDispose(), and RTT::ExecutionEngine::removeFunction().

bool RTT::ExecutionEngine::runFunction ( base::ExecutableInterface f)
virtualinherited

Run a given function in step() or loop().

The function may only be destroyed after the ExecutionEngine is stopped or removeFunction() was invoked. The number of functions the Processor can run in parallel can be increased with setMaxFunctions().

Returns
false if the Engine is not running or the 'pending' queue is full.
See also
removeFunction(), setMaxFunctions()

Definition at line 132 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::f_queue, RTT::base::TaskCore::FatalError, RTT::base::RunnableInterface::getActivity(), RTT::base::ExecutableInterface::loaded(), RTT::base::TaskCore::mTaskState, RTT::ExecutionEngine::taskc, and RTT::base::ActivityInterface::trigger().

Referenced by RTT::scripting::CallFunction::execute(), RTT::scripting::ScriptingService::loadFunctions(), RTT::scripting::ScriptingService::loadProgram(), and RTT::scripting::ScriptingService::recursiveLoadStateMachine().

void RTT::ExecutionEngine::setActivity ( base::ActivityInterface task)
virtualinherited

Overwritten version of RTT::base::RunnableInterface::setActivity().

This version will also set the master ExecutionEngine if the new activity is a SlaveActivity that runs an ExecutionEngine.

Parameters
taskThe ActivityInterface running this interface.

Reimplemented from RTT::base::RunnableInterface.

Definition at line 287 of file ExecutionEngine.cpp.

References RTT::extras::SlaveActivity::getMaster(), RTT::base::ActivityInterface::getRunner(), RTT::base::RunnableInterface::setActivity(), and RTT::ExecutionEngine::setMaster().

void RTT::ExecutionEngine::setExceptionTask ( )
inherited

Set the 'owner' task in the exception state.

Definition at line 438 of file ExecutionEngine.cpp.

References RTT::Error, RTT::base::TaskCore::exception(), RTT::TaskContext::getName(), and RTT::ExecutionEngine::taskc.

Referenced by RTT::base::OperationCallerInterface::reportError().

void RTT::ExecutionEngine::setMaster ( ExecutionEngine master)
inherited

Set the master ExecutionEngine.

If set, all incoming messages are forwarded to the master.

Parameters
masterThe new master ExecutionEngine.

Definition at line 282 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::mmaster.

Referenced by RTT::ExecutionEngine::setActivity().

void RTT::ExecutionEngine::step ( )
protectedvirtualinherited

Executes (in that order) Messages, Functions and updateHook() functions of this TaskContext and its children.

Implements RTT::base::RunnableInterface.

Definition at line 347 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::processChildren(), RTT::ExecutionEngine::processFunctions(), and RTT::ExecutionEngine::processMessages().

bool RTT::ExecutionEngine::stopTask ( base::TaskCore task)
inherited

Stops executing the updateHook of task.

This is an explicit synchronisation point, which guarantees that updateHook is no longer executed when this function returns true.

Parameters
taskThe Task calling this function and whose updateHook should no longer be executed.
Returns
true if it's updateHook() is no longer being executed, false otherwise.

Definition at line 427 of file ExecutionEngine.cpp.

References RTT::base::RunnableInterface::getActivity(), and RTT::base::ActivityInterface::start().

void RTT::ExecutionEngine::waitAndProcessFunctions ( boost::function< bool(void)> const &  pred)
protectedinherited

Call this if you wish to block on a function completing in the Execution Engine and execute it.

Parameters
predAs long as !pred() waits and processes functions. If pred() == true when entering this function, then no functions will be processed and this function returns immediately.

This function is for internal use only and is required for asynchronous function invocations.

Note
waitAndProcessFunctions will call in turn this->processFunctions() and may as a consequence recurse if we get an asynchronous call-back.

Definition at line 329 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::msg_cond, RTT::ExecutionEngine::msg_lock, RTT::ExecutionEngine::processFunctions(), and RTT::os::Condition::wait().

Referenced by RTT::ExecutionEngine::waitForFunctions().

void RTT::ExecutionEngine::waitAndProcessMessages ( boost::function< bool(void)> const &  pred)
protectedinherited

Call this if you wish to block on a message arriving in the Execution Engine and execute it.

Parameters
predAs long as !pred() waits and processes messages. If pred() == true when entering this function, then no messages will be processed and this function returns immediately.

This function is for internal use only and is required for asynchronous method invocations.

Note
waitAndProcessMessages will call in turn this->processMessages() and may as a consequence recurse if we get an asynchronous call-back.

Definition at line 311 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::msg_cond, RTT::ExecutionEngine::msg_lock, RTT::ExecutionEngine::processMessages(), and RTT::os::Condition::wait().

Referenced by RTT::ExecutionEngine::waitForMessages().

void RTT::ExecutionEngine::waitForFunctions ( const boost::function< bool(void)> &  pred)
inherited

Call this if you wish to block on a function completing in the Execution Engine.

Each time a function completes, waitForFunctions will return when pred() returns true.

Parameters
predAs long as !pred() blocks the calling thread. If pred() == true when entering this function, returns immediately.

This function is for internal use only and is required for asynchronous function invocations.

Definition at line 274 of file ExecutionEngine.cpp.

References RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::waitAndProcessFunctions(), and RTT::ExecutionEngine::waitForMessagesInternal().

Referenced by RTT::scripting::CallFunction::execute().

void RTT::ExecutionEngine::waitForMessages ( const boost::function< bool(void)> &  pred)
inherited

Call this if you wish to block on a message arriving in the Execution Engine.

Each time one or more messages are processed, waitForMessages will return when pred() returns true.

Parameters
predAs long as !pred() blocks the calling thread. If pred() == true when entering this function, returns immediately.

This function is for internal use only and is required for asynchronous method invocations.

Definition at line 259 of file ExecutionEngine.cpp.

References RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::mmaster, RTT::ExecutionEngine::waitAndProcessMessages(), RTT::ExecutionEngine::waitForMessages(), and RTT::ExecutionEngine::waitForMessagesInternal().

Referenced by RTT::internal::LocalOperationCallerImpl< FunctionT >::collect_impl(), RTT::ExecutionEngine::removeFunction(), and RTT::ExecutionEngine::waitForMessages().

void RTT::ExecutionEngine::waitForMessagesInternal ( boost::function< bool(void)> const &  pred)
protectedinherited

Call this if you wish to block on a message arriving in the Execution Engine.

Each time one or more messages are processed, waitForMessages will return when pred() returns true.

Parameters
predAs long as !pred() blocks the calling thread. If pred() == true when entering this function, the returns immediately.

This function is for internal use only and is required for asynchronous method invocations.

Note
waitForMessages requires another thread to execute processMessages() and may therefor not be called from within the component's Thread. Use waitAndProcessMessages() instead.

Definition at line 299 of file ExecutionEngine.cpp.

References RTT::ExecutionEngine::msg_cond, RTT::ExecutionEngine::msg_lock, and RTT::os::Condition::wait().

Referenced by RTT::ExecutionEngine::waitForFunctions(), and RTT::ExecutionEngine::waitForMessages().

Member Data Documentation

std::vector<base::TaskCore*> RTT::ExecutionEngine::children
protectedinherited
internal::MWSRQueue<base::ExecutableInterface*>* RTT::ExecutionEngine::f_queue
protectedinherited
ExecutionEngine* RTT::ExecutionEngine::mmaster
protectedinherited

A master ExecutionEngine which should process our messages.

This is used for ExecutionEngines running in a SlaveActivity which forward incoming messages to their master engine.

Definition at line 270 of file ExecutionEngine.hpp.

Referenced by RTT::ExecutionEngine::process(), RTT::ExecutionEngine::setMaster(), and RTT::ExecutionEngine::waitForMessages().

internal::MWSRQueue<base::DisposableInterface*>* RTT::ExecutionEngine::mqueue
protectedinherited
os::Condition RTT::ExecutionEngine::msg_cond
protectedinherited
os::Mutex RTT::ExecutionEngine::msg_lock
protectedinherited
base::TaskCore* RTT::ExecutionEngine::taskc
protectedinherited

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