Orocos Real-Time Toolkit
2.5.0
|
A process-wide execution engine that processes every asynchronous operation that is not being processed by a TaskContext. More...
#include <rtt/internal/GlobalEngine.hpp>
Public Member Functions | |
base::TaskCore * | getParent () |
The base::TaskCore which created this ExecutionEngine. | |
virtual void | addChild (base::TaskCore *tc) |
Add a base::TaskCore to execute. | |
virtual void | removeChild (base::TaskCore *tc) |
Remove a base::TaskCore from execution. | |
base::TaskCore * | getTaskCore () const |
Returns the owner of this execution engine. | |
virtual bool | process (base::DisposableInterface *c) |
Queue and execute (process) a given message. | |
virtual bool | runFunction (base::ExecutableInterface *f) |
Run a given function in step() or loop(). | |
virtual bool | removeFunction (base::ExecutableInterface *f) |
Remove a running function added with runFunction. | |
virtual bool | removeSelfFunction (base::ExecutableInterface *f) |
Self-removal for a running function added with runFunction. | |
void | waitForMessages (const boost::function< bool(void)> &pred) |
Call this if you wish to block on a message arriving in the Execution Engine. | |
void | waitForFunctions (const boost::function< bool(void)> &pred) |
Call this if you wish to block on a function completing in the Execution Engine. | |
bool | stopTask (base::TaskCore *task) |
Stops executing the updateHook of task. | |
virtual void | loop () |
The method that will be executed once when this class is run in a non periodic thread. | |
virtual os::ThreadInterface * | getThread () const |
Get the thread this object is run in. | |
ActivityInterface * | getActivity () const |
Query for the task this interface is run in. | |
virtual void | setActivity (ActivityInterface *task) |
Set the task this interface is run in. | |
Static Public Member Functions | |
static RTT_API ExecutionEngine * | Instance () |
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. | |
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. | |
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. | |
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. | |
virtual void | step () |
Executes (in that order) Messages, Functions and updateHook() functions of this TaskContext and its children. | |
virtual bool | breakLoop () |
This method is called by the framework to break out of the loop() method. | |
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. | |
virtual bool | hasWork () |
This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again). | |
Protected Attributes | |
base::TaskCore * | taskc |
The parent or 'owner' of this ExecutionEngine, may be null. | |
internal::MWSRQueue < base::DisposableInterface * > * | mqueue |
Our Message queue. | |
std::vector< base::TaskCore * > | children |
internal::MWSRQueue < base::ExecutableInterface * > * | f_queue |
Stores all functions we're executing. | |
os::Mutex | msg_lock |
os::Condition | msg_cond |
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.
bool RTT::ExecutionEngine::breakLoop | ( | ) | [protected, virtual, inherited] |
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.
Reimplemented from RTT::base::RunnableInterface.
Definition at line 386 of file ExecutionEngine.cpp.
References RTT::base::TaskCore::breakUpdateHook(), and RTT::ExecutionEngine::taskc.
ActivityInterface * RTT::base::RunnableInterface::getActivity | ( | ) | const [inline, inherited] |
Query for the task this interface is run in.
Zero denotes that no task is present to run it, and hence no detailed information is available.
Definition at line 167 of file RunnableInterface.hpp.
Referenced by RTT::base::TaskCore::activate(), RTT::base::TaskCore::fatal(), RTT::TaskContext::getActivity(), RTT::base::TaskCore::getCpuAffinity(), RTT::base::TaskCore::getPeriod(), RTT::base::TaskCore::isActive(), RTT::ExecutionEngine::process(), RTT::ExecutionEngine::removeFunction(), RTT::ExecutionEngine::runFunction(), RTT::base::TaskCore::setCpuAffinity(), RTT::base::TaskCore::setPeriod(), RTT::ExecutionEngine::stopTask(), RTT::base::TaskCore::trigger(), RTT::base::TaskCore::update(), RTT::ExecutionEngine::waitForFunctions(), and RTT::ExecutionEngine::waitForMessages().
os::ThreadInterface * RTT::RunnableInterface::getThread | ( | ) | const [virtual, inherited] |
Get the thread this object is run in.
Definition at line 78 of file CoreRunnableInterface.cpp.
References RTT::base::ActivityInterface::thread().
bool RTT::ExecutionEngine::hasWork | ( | ) | [protected, virtual, inherited] |
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.
Reimplemented from RTT::base::RunnableInterface.
Definition at line 211 of file ExecutionEngine.cpp.
References RTT::internal::AtomicMWSRQueue< T >::isEmpty(), and RTT::ExecutionEngine::mqueue.
void RTT::RunnableInterface::loop | ( | ) | [virtual, inherited] |
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 | ) | [virtual, inherited] |
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().
Definition at line 238 of file ExecutionEngine.cpp.
References RTT::os::Condition::broadcast(), RTT::internal::AtomicMWSRQueue< T >::enqueue(), RTT::base::TaskCore::FatalError, RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::mqueue, RTT::ExecutionEngine::taskc, and RTT::base::ActivityInterface::trigger().
Referenced by RTT::internal::LocalOperationCallerImpl< FunctionT >::executeAndDispose(), and RTT::ExecutionEngine::removeFunction().
bool RTT::ExecutionEngine::removeFunction | ( | base::ExecutableInterface * | f | ) | [virtual, inherited] |
Remove a running function added with runFunction.
This method is only required if the function is to be destroyed and is still present in the Engine.
Definition at line 161 of file ExecutionEngine.cpp.
References RTT::base::RunnableInterface::getActivity(), RTT::base::ActivityInterface::isActive(), RTT::base::ExecutableInterface::isLoaded(), RTT::ExecutionEngine::process(), RTT::ExecutionEngine::removeSelfFunction(), RTT::base::ExecutableInterface::unloaded(), and RTT::ExecutionEngine::waitForMessages().
Referenced by RTT::scripting::ScriptingService::unloadProgram(), and RTT::scripting::StateMachine::~StateMachine().
bool RTT::ExecutionEngine::removeSelfFunction | ( | base::ExecutableInterface * | f | ) | [virtual, inherited] |
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 187 of file ExecutionEngine.cpp.
References RTT::internal::AtomicMWSRQueue< T >::dequeue(), RTT::internal::AtomicMWSRQueue< T >::enqueue(), RTT::ExecutionEngine::f_queue, and RTT::internal::AtomicMWSRQueue< T >::size().
Referenced by RTT::ExecutionEngine::removeFunction().
bool RTT::ExecutionEngine::runFunction | ( | base::ExecutableInterface * | f | ) | [virtual, inherited] |
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().
Definition at line 132 of file ExecutionEngine.cpp.
References RTT::internal::AtomicMWSRQueue< T >::enqueue(), RTT::ExecutionEngine::f_queue, RTT::base::TaskCore::FatalError, RTT::base::RunnableInterface::getActivity(), RTT::base::ExecutableInterface::loaded(), RTT::ExecutionEngine::taskc, and RTT::base::ActivityInterface::trigger().
Referenced by RTT::scripting::ScriptingService::loadFunctions(), and RTT::scripting::ScriptingService::loadProgram().
void RTT::RunnableInterface::setActivity | ( | ActivityInterface * | task | ) | [virtual, inherited] |
Set the task this interface is run in.
A Zero means no task is running it.
task | The ActivityInterface running this interface. |
Definition at line 69 of file CoreRunnableInterface.cpp.
References RTT::base::ActivityInterface::disableRun().
Referenced by RTT::base::ActivityInterface::run().
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.
task | The Task calling this function and whose updateHook should no longer be executed. |
Definition at line 396 of file ExecutionEngine.cpp.
References RTT::base::RunnableInterface::getActivity(), and RTT::base::ActivityInterface::start().
void RTT::ExecutionEngine::waitAndProcessFunctions | ( | boost::function< bool(void)> const & | pred | ) | [protected, inherited] |
Call this if you wish to block on a function completing in the Execution Engine and execute it.
pred | As 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.
Definition at line 300 of file ExecutionEngine.cpp.
References RTT::os::Condition::wait().
Referenced by RTT::ExecutionEngine::waitForFunctions().
void RTT::ExecutionEngine::waitAndProcessMessages | ( | boost::function< bool(void)> const & | pred | ) | [protected, inherited] |
Call this if you wish to block on a message arriving in the Execution Engine and execute it.
pred | As 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.
Definition at line 282 of file ExecutionEngine.cpp.
References 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.
pred | As 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 261 of file ExecutionEngine.cpp.
References RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::waitAndProcessFunctions(), and RTT::ExecutionEngine::waitForMessagesInternal().
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.
pred | As 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 252 of file ExecutionEngine.cpp.
References RTT::base::RunnableInterface::getActivity(), RTT::ExecutionEngine::waitAndProcessMessages(), and RTT::ExecutionEngine::waitForMessagesInternal().
Referenced by RTT::ExecutionEngine::removeFunction().
void RTT::ExecutionEngine::waitForMessagesInternal | ( | boost::function< bool(void)> const & | pred | ) | [protected, 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.
pred | As 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.
Definition at line 270 of file ExecutionEngine.cpp.
References RTT::os::Condition::wait().
Referenced by RTT::ExecutionEngine::waitForFunctions(), and RTT::ExecutionEngine::waitForMessages().