|
fiber
|
A TaskBase (short for coroutine task) is the root of a linked list of nested coroutines.
More...
#include <Coroutine.hpp>
Classes | |
| struct | larger_ready_time_s |
| struct | less_priority_s |
Public Member Functions | |
| constexpr | TaskBase ()=default |
| constexpr | TaskBase (const TaskBase &)=delete |
| constexpr TaskBase & | operator= (const TaskBase &)=delete |
| constexpr | TaskBase (TaskBase &&other) noexcept |
| TaskBase & | operator= (TaskBase &&other) noexcept |
| template<class F, class... Args> requires std::invocable<F, Args...> && std::same_as<std::invoke_result_t<F, Args...>, Coroutine<fiber::Exit>> | |
| constexpr | TaskBase (std::string_view task_name, fiber::StackAllocatorExtern *frame_allocator, F &&function, Args &&... args) |
| constructor to create a priority-based task with the lowest priority | |
| template<class F, class... Args> requires std::invocable<F, Args...> && std::same_as<std::invoke_result_t<F, Args...>, Coroutine<fiber::Exit>> | |
| constexpr | TaskBase (std::string_view task_name, uint16_t priority, fiber::StackAllocatorExtern *frame_allocator, F &&function, Args &&... args) |
| constructor to create a priority-based task that starts immediatelly | |
| template<class F, class... Args> requires std::invocable<F, Args...> && std::same_as<std::invoke_result_t<F, Args...>, Coroutine<fiber::Exit>> | |
| constexpr | TaskBase (std::string_view task_name, TimePoint ready, fiber::StackAllocatorExtern *frame_allocator, F &&function, Args &&... args) |
| constructor to create a priority-based task that starts at a certain time point in the future | |
| template<class F, class... Args> requires std::invocable<F, Args...> && std::same_as<std::invoke_result_t<F, Args...>, Coroutine<fiber::Exit>> | |
| constexpr | TaskBase (std::string_view task_name, TimePoint ready, TimePoint deadline, fiber::StackAllocatorExtern *frame_allocator, F &&function, Args &&... args) |
| constructor to create a real-time deadline-based task | |
| template<class F, class... Args> requires std::invocable<F, Args...> && std::same_as<std::invoke_result_t<F, Args...>, Coroutine<fiber::Exit>> | |
| constexpr | TaskBase (std::string_view task_name, TimePoint ready, Duration deadline, fiber::StackAllocatorExtern *frame_allocator, F &&function, Args &&... args) |
| constructor to create a real-time deadline-based task | |
| virtual | ~TaskBase () |
| virtual bool | missed_deadline (fiber::Duration d) |
| Overrideable: Gets called if the deadline has been missed and decides wether the task should still execute or not. | |
| virtual Schedule | next_schedule (Schedule previous_schedule, ExecutionTime previous_execution) |
Overrideable: Gets called after a co_await NextCycle; to calculate the schedule of the next cycle. | |
| constexpr unsigned int | id () const |
| returns the assigned id of the task. | |
| constexpr bool | is_deadline_based () const |
| constexpr bool | is_priority_based () const |
| constexpr std::string_view | name () const |
| returns the name of the task | |
| constexpr std::size_t | max_frame_size () const |
| returns the maximal allocatable size of the frame (stack allocator) | |
| constexpr std::size_t | allocated_frame_size () const |
| returns the allocated size of the frame (stack allocator) | |
| constexpr std::size_t | max_allocated_frame_size () const |
| returns the maximal allocated size in the frame since construction (stack allocator) | |
| constexpr void | signal (const CoSignal &signal) |
| sets a coroutine control signal. | |
| constexpr const CoSignal | get_signal () |
| reads and clears the signal | |
| constexpr void | destroy () |
| destroys all contained coroutines | |
| constexpr void | register_leaf (CoroutineNode *leaf) noexcept |
| Registers the leaf nested coroutine that serves as the resume point after suspensions. | |
| template<class T> | |
| constexpr void | register_leaf (const T *obj, bool(*func)(const T *obj)) noexcept |
| Registers a leaf awaitable that will be waited on before resuming its parents coroutine. | |
| void | resume () |
| resumes the task/coroutine | |
| bool | is_resumable () const |
returns true if the awaitable that this task is waiting on is ready and .resume() can be called again | |
| constexpr bool | is_awaiting () const |
returns true if the awaitable that this task is waiting on is still waiting for completion - aka. this task is not resumable | |
| constexpr bool | is_done () const |
returns true if the main/root coroutine is done - thus the task is done | |
| constexpr bool | await_ready () const noexcept |
same as is_done() but for interoperability with co_await | |
| constexpr Exit | await_resume () |
interoperability with co_await | |
| constexpr Exit | exit_status () |
| void | handle_exception (std::exception_ptr except_ptr) |
| exception handler - will be called if an un-catched exception in a coroutine arises | |
| TimePoint | ready_time () const |
| TimePoint | deadline () const |
| uint32_t | priority () const |
| bool | immediatelly_ready () const |
Public Attributes | |
| std::string_view | _task_name = "" |
| fiber::StackAllocatorExtern * | _frame_allocator |
| Coroutine< fiber::Exit > | _main_coroutine |
| CoroutineNode * | _leaf_coroutine = nullptr |
| bool(* | _leaf_awaitable_ready_func )(const void *_leaf_awaitable_obj) = nullptr |
| const void * | _leaf_awaitable_obj = nullptr |
| CoSignal | _signal |
| uint32_t | _priority = 0 |
| Schedule | _schedule |
| TimePoint | _execution_start |
| uint16_t | _id = 0 |
| bool | _instant_resume = false |
| bool | _immediatelly_ready = false |
Static Public Attributes | |
| static constexpr uint32_t | _deadline_priority = std::numeric_limits<uint32_t>::max() |
A TaskBase (short for coroutine task) is the root of a linked list of nested coroutines.
A TaskBase contains one or more (nested) coroutines in an acyclic graph. It will always resume the last/leaf coroutine and is done onece all coroutines have co_retuned.
A TaskBase is itsef an AwaitableNode and thus might be co_awaited by another task. This might be useful, for example if one task issues 3 other tasks to the scheduler, and the co_awaits all of them to continue its own execution only once all are finished.
The leaf coroutine can communicate to the TaskBase via the interface provided by the AwaitableNode that is co_awaited. Through co_await the leaf coroutine can send a signal to the TaskBase (and thus the scheduler) to tell that it is awaiting on some external task, hardware, I/O, etc.
You might customise the behaviour of the task by overloading the error handler, that will be invoked on uncaught exceptions.
| N | The number of bytes used for the tasks frame allocator |
|
constexprdefault |
|
constexprdelete |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
constructor to create a priority-based task with the lowest priority
Defaults to priority 1 (2nd lowest priority level, lowest priority is 0)
|
inlineconstexpr |
constructor to create a priority-based task that starts immediatelly
|
inlineconstexpr |
constructor to create a priority-based task that starts at a certain time point in the future
Defaults to priority 1 (2nd lowest priority level, lowest priority is 0)
|
inlineconstexpr |
constructor to create a real-time deadline-based task
deadline based tasks automatically have int_max assigned to their priority (highest priority).
|
inlineconstexpr |
constructor to create a real-time deadline-based task
deadline based tasks automatically have int_max assigned to their priority (highest priority).
|
inlinevirtual |
|
inlineconstexpr |
returns the allocated size of the frame (stack allocator)
|
inlineconstexprnoexcept |
same as is_done() but for interoperability with co_await
|
constexpr |
interoperability with co_await
|
inline |
|
inlineconstexpr |
destroys all contained coroutines
|
constexpr |
|
inlineconstexpr |
reads and clears the signal
| void fiber::TaskBase::handle_exception | ( | std::exception_ptr | except_ptr | ) |
exception handler - will be called if an un-catched exception in a coroutine arises
|
inlineconstexpr |
returns the assigned id of the task.
Has likely been assigned by the scheduler
|
inline |
|
inlineconstexpr |
returns true if the awaitable that this task is waiting on is still waiting for completion - aka. this task is not resumable
equivalent to !task->is_resumable()
|
inlineconstexpr |
|
inlineconstexpr |
returns true if the main/root coroutine is done - thus the task is done
|
inlineconstexpr |
| bool fiber::TaskBase::is_resumable | ( | ) | const |
returns true if the awaitable that this task is waiting on is ready and .resume() can be called again
also returns true if there is currently no awaitable that is being waited on.
|
inlineconstexpr |
returns the maximal allocated size in the frame since construction (stack allocator)
|
inlineconstexpr |
returns the maximal allocatable size of the frame (stack allocator)
|
inlinevirtual |
Overrideable: Gets called if the deadline has been missed and decides wether the task should still execute or not.
| d | The duration/time that passed since the deadline |
The default version will always return true to continue the task
true) or not (false)
|
inlineconstexpr |
returns the name of the task
|
inlinevirtual |
Overrideable: Gets called after a co_await NextCycle; to calculate the schedule of the next cycle.
Note that previous_execution.end is equivalent to the current time .aka now()
| previous_schedule | the previous schedule of this task |
| previous_execution | the previous execution time from the start of the cycle to the end of the cycle |
|
inline |
|
inline |
|
inlineconstexprnoexcept |
Registers a leaf awaitable that will be waited on before resuming its parents coroutine.
Meant to be called by the Awaitable
| awaitable | The awaitable that will be waited on |
|
inlineconstexprnoexcept |
Registers the leaf nested coroutine that serves as the resume point after suspensions.
Meant to be called by the Coroutine
| leaf | a coroutine handle to the leaf tasks |
| void fiber::TaskBase::resume | ( | ) |
resumes the task/coroutine
This the only resume point for the whole coroutine chain. Every coroutine and nested coroutine suspends to here and will be executed/resumed from here by resuming the leaf/tail of the coroutine linked list.
Note: a task needs to be resumeable, that is
is_resumeable()returnstruebefore calling this method. Otherwise an assertion is thrown atASSERTION_LEVEL_O1or higher - if lower: Undefined behaviour UB ⚠.
| An | AssertionFailuer if resumed while is_resumeable() is false, but only in ASSERTION_LEVEL_O1 or higher |
|
inlineconstexpr |
sets a coroutine control signal.
Used by the coroutine or awaitable to set a control signal. Can be used to influence the runtime behaviour of the task, or the way the scheduler continues scheduling it.
|
staticconstexpr |
| TimePoint fiber::TaskBase::_execution_start |
| fiber::StackAllocatorExtern* fiber::TaskBase::_frame_allocator |
| uint16_t fiber::TaskBase::_id = 0 |
| bool fiber::TaskBase::_immediatelly_ready = false |
| bool fiber::TaskBase::_instant_resume = false |
| const void* fiber::TaskBase::_leaf_awaitable_obj = nullptr |
| bool(* fiber::TaskBase::_leaf_awaitable_ready_func) (const void *_leaf_awaitable_obj) = nullptr |
| CoroutineNode* fiber::TaskBase::_leaf_coroutine = nullptr |
| Coroutine<fiber::Exit> fiber::TaskBase::_main_coroutine |
| uint32_t fiber::TaskBase::_priority = 0 |
| Schedule fiber::TaskBase::_schedule |
| CoSignal fiber::TaskBase::_signal |
| std::string_view fiber::TaskBase::_task_name = "" |