A class representing a "running" task, with added functionality to post events requesting execution of external code within it.
More...
|
|
inline ::mel::core::ThreadId | getOwnerThreadId () const |
| |
| void | setOwnerThreadId (mel::core::ThreadId tid) |
| |
| void | setDefaultFactory (ProcessFactory *factory) |
| | Change default factory used to create task through post and fireAndForget. More...
|
| |
|
const ProcessFactory * | getDefaultFactory () const |
| | Retrieves the current default factory for tasks.
|
| |
| void | postTask (std::shared_ptr< Process > process, unsigned int startTime=0) |
| |
|
| Runnable (RunnableCreationOptions opts) |
| | Constructor.
|
| |
| template<bool ignoreNoThrow = false, class AllocatorType = ::mel::tasking::DefaultAllocator, class F , class KF = const std::function<bool()>&> |
| std::shared_ptr< Process > | post (F &&task_proc, KF &&killFunction=killFalse, unsigned int period=0, unsigned int startTime=0) |
| |
| template<bool ignoreNoThrow = false, class AllocatorType = ::mel::tasking::DefaultAllocator, class F , class KF = const std::function<bool()>&> |
| std::shared_ptr< Process > | fireAndForget (F &&task_proc, unsigned int startTime=0, KF &&killFunction=killTrue) |
| | Convenient function to post no periodic task with signature void f() More...
|
| |
| template<class TRet , class F , class KF = const std::function<bool()>&> |
| Future< TRet > | execute (F &&function, KF &&killFunction=killFalse) noexcept |
| | Executes a function in a context of the Runnable. If this Runnable is in the same thread than caller then, depending on forcepost parameter, the functor will be executed directly (so Future<TRet> will be always available at return) or posted (so caller will need to wait on this Future or whatever other mechanism) More...
|
| |
| template<class TRet , class F , class KF = const std::function<bool()>&> |
| Future< TRet > | execute (F &&function, Future< TRet >, KF &&killFunction=killFalse) noexcept |
| | Overload where output Future is given With this overload the given Future is fille with result from function. More...
|
| |
| const ProcessScheduler & | getScheduler () const |
| |
|
ProcessScheduler & | getScheduler () |
| |
| void | setTimer (std::shared_ptr< Timer > timer) |
| |
|
const std::shared_ptr< Timer > | getTimer () const |
| |
|
std::shared_ptr< Timer > | getTimer () |
| |
|
unsigned int | getPendingTaskCount () const |
| |
|
unsigned int | getActiveTaskCount () const |
| |
|
unsigned int | getMaxPoolSize () const |
| |
A class representing a "running" task, with added functionality to post events requesting execution of external code within it.
Any external thread can request any other runnable the execution of any piece of code through Runnable::post(...) methods.
The execution requests are internaly stored in a ProcessScheduler,and processed anytime after the call is made.
The first method simply blocks the calling thread until the requested task has been completed, or a timeout is reached. The second method just checks for task completion and returns inmediately.
For this scheme to work, subclasses must ensure that Runnable::processTasks(...) method is called often enough to satisfy the external execution requirements. Otherwise, an IllegalStateException maybe raised to calling threads when a new code execution is made and there is not enough room for the request.
template<bool ignoreNoThrow, class AllocatorType , class F , class KF >
| std::shared_ptr< Process > mel::tasking::Runnable::post |
( |
F && |
task_proc, |
|
|
KF && |
killFunction = killFalse, |
|
|
unsigned int |
period = 0, |
|
|
unsigned int |
startTime = 0 |
|
) |
| |
Posts a new execution request over a functor The execution is NOT guaranteed to be taken into account inmediatly. By default, a ::mel::tasking::_private::RunnableTask is created, which is intended to be used with a custom memory manager for performance reasons. Users can provide their own AllocatorType class to change the way the underlying Process is created, either by creating a custom specialization of GenericProcess or/and using a custom memory pool
- See also
- RTMemPool
- Template Parameters
-
| ignoreNoThrow | If false, an assertion is raised if callable task_proc is not noexcept. Default value = false |
- Parameters
-
| [in] | task_proc | the functor to be executed. It has signature: bool (unsigned int msecs, Process*) |
| [in] | killFunction. | Functor with signature bool () used when kill is executed while doing function. |
| [in] | period | Milliseconds |
| [in] | startTime | milliseconds to begin task |
- Returns
- the process created for this task