![]() |
AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library. Threads-like task objects evolving through user-defined states. |
A wrapper for a (member) function to be executed by the AIThreadPool.
An AIPackagedTask is supposed to be a member of a class (e.g. MyTask) derived from AIStatefulTask. The this pointer of that task should be passed to the constructor, along with a function to be called and a handle of the queue to add it to (as obtained by a call to AIThreadPool::new_queue()).
It is possible to use a pointer to a free function or to the member function of a given object. In both cases with arbitrary signature.
For example, suppose you have some object foo of type Foo with a member function called retrieve that has the signature bool Foo::retrieve(int, double), whatever those parameters may mean. Then you could do:
where as usual retrieve_condition should be different from any other condition bits that this task is using. And where queue_handle is a handle that was previously returned by AIThreadPool::new_queue().
Then this function can be called (repeatedly, with different parameters if need be) from multiplex_impl as follows:
#include <AIPackagedTask.h>


Public Member Functions | |
| AIPackagedTask (AIStatefulTask *parent_task, AIStatefulTask::condition_type condition, R(*fp)(Args...), AIQueueHandle object_queue_handle) | |
| template<class C > | |
| AIPackagedTask (AIStatefulTask *parent_task, AIStatefulTask::condition_type condition, C *object, R(C::*memfp)(Args...), AIQueueHandle object_queue_handle) | |
| ~AIPackagedTask () | |
| Destructor. | |
| void | swap (AIPackagedTask &other) noexcept |
| Exchange the state with that of other. | |
| void | operator() (Args... args) |
| Copy the arguments. | |
| bool | dispatch () |
| R | get () const |
Additional Inherited Members | |
Public Types inherited from AIFriendOfStatefulTask | |
| using | state_type = AIStatefulTask::state_type |
| Proxy for AIStatefulTask::state_type. | |
| using | condition_type = AIStatefulTask::condition_type |
| Proxy for AIStatefulTask::condition_type. | |
Protected Member Functions inherited from AIFriendOfStatefulTask | |
| AIFriendOfStatefulTask (AIStatefulTask *task) | |
| Construct a friend of task. | |
| void | set_state (state_type new_state) |
| Proxy for AIStatefulTask::set_state. | |
| void | wait (condition_type conditions) |
| Proxy for AIStatefulTask::wait. | |
| void | wait_until (AIWaitConditionFunc const &wait_condition, condition_type conditions) |
| Proxy for AIStatefulTask::wait_until. | |
| void | wait_until (AIWaitConditionFunc const &wait_condition, condition_type conditions, state_type new_state) |
| Proxy for AIStatefulTask::wait_until. | |
| void | finish () |
| Proxy for AIStatefulTask::finish. | |
| void | yield () |
| Proxy for AIStatefulTask::yield. | |
| void | target (AIEngine *engine) |
| Proxy for AIStatefulTask::target. | |
| void | yield (AIEngine *engine) |
| Proxy for AIStatefulTask::yield. | |
| void | yield_frame (AIEngine *engine, unsigned int frames) |
| Proxy for AIStatefulTask::yield_frame. | |
| void | yield_ms (AIEngine *engine, unsigned int ms) |
| Proxy for AIStatefulTask::yield_ms. | |
| bool | yield_if_not (AIEngine *engine) |
| Proxy for AIStatefulTask::yield_if_not. | |
Protected Attributes inherited from AIFriendOfStatefulTask | |
| AIStatefulTask * | m_task |
| The base class of the object that this object is a member of. | |
|
inline |
Construct a packaged task for a free function.
| parent_task | The task that dispatch will call wait_until and signal on. |
| condition | The condition to use for wait_until and signal. |
| fp | A pointer to the function that needs to be called. |
| object_queue_handle | A handle to the AIObjectQueue that the delayed function should be placed in. |
|
inline |
Construct a packaged task for a member function.
| parent_task | The task that dispatch will call wait_until and signal on. |
| condition | The condition to use for wait_until and signal. |
| object | Pointer to the object of which the member function must be called. |
| memfp | A pointer to the member function that needs to be called. |
| object_queue_handle | A handle to the AIObjectQueue that the delayed function should be placed in. |
| bool AIPackagedTask< R(Args...)>::dispatch |
Put the task in a queue for execution in a different thread.
Actually queue the task in the AIObjectQueue whose handle was passed to the constructor and halt the parent_task as passed to the constructor until this task is finished.
|
inline |
Read out the result of the function.
May only be called after parent_task->signal(condition) was called.