Mercury Currency Engine
|
fundamental structure for allowing blocking of coroutines running on a scheduler More...
#include <scheduler.hpp>
Classes | |
struct | continuation |
Static Public Member Functions | |
static void | suspend (continuation &c) |
the fundamental operation required for blocking a coroutine running in a scheduler More... | |
fundamental structure for allowing blocking of coroutines running on a scheduler
Ths object is used by the scheduler::parkable
object, which implements high level blocking functionality needed by both coroutines and threads.
In comparison, this is a more basic type is only for blocking coroutines, and requires more manual work because of its more generic nature. However, this type is exposed in case it is required by user code.
All higher level coroutine blocking mechanics are built on this structure. A mutable reference to a park::continuation is passed to scheduler::request_park()
, which will register the continuation with the scheduler
running on the current thread and yield()
control to said scheduler
, suspending execution of the calling coroutine.
When the scheduler
resumes control, it will assign the just running coroutine to the specified std::unique_ptr<coroutine>
, and will assign its smart pointer to the specified std::shared_ptr<scheduler
. At this point, control of the given coroutine completely leaves the scheduler
, it is up to the destination code to decide what to do with the coroutine.
After passing the coroutine to its destination, the specified cleanup()
method will be called with memory
. This can be any operation, accepting any data as an argument. A common usecase is to unlock an atomic lock object.
|
inlinestatic |
the fundamental operation required for blocking a coroutine running in a scheduler
Direct usage of this is not recommended unless it is truly required, prefer scheduler::parkable instead.
It is an error if this is called outside of a coroutine running in a scheduler.