|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
One strand over a morph executor, usable wherever a morph executor is: the owner a component's state belongs to. More...
#include <owner_strand.hpp>
Public Member Functions | |
| OwnerStrand (::morph::exec::IExecutor &base) | |
| OwnerStrand (const OwnerStrand &)=delete | |
| OwnerStrand & | operator= (const OwnerStrand &)=delete |
| OwnerStrand (OwnerStrand &&)=delete | |
| OwnerStrand & | operator= (OwnerStrand &&)=delete |
| ~OwnerStrand () override | |
| Closes the strand: what is still queued is dropped, and a task running on another thread is waited for. | |
| void | post (std::function< void()> task) override |
Queues task after everything posted before it. A throw out of it is logged. Dropped once the strand is closed. | |
| template<typename F> | |
| void | postTask (F &&task) |
Queues task, held by value in the strand's one allocation for it, after everything posted before it. A throw out of it is logged. Dropped once the strand is closed. | |
| bool | runningHere () const noexcept |
| Whether the calling thread is inside one of this strand's tasks. | |
| bool | idle () const |
| Whether nothing is queued or running. | |
| void | close () |
| Closes the strand, as the destructor does. Idempotent. | |
| void | seal () |
| Refuses the strand's try-forms and keeps running what is queued; post is still admitted until close(). Idempotent. | |
| Public Member Functions inherited from morph::exec::IExecutor | |
| IExecutor (const IExecutor &)=delete | |
| IExecutor & | operator= (const IExecutor &)=delete |
| IExecutor (IExecutor &&)=delete | |
| IExecutor & | operator= (IExecutor &&)=delete |
| virtual bool | isSerial () const noexcept |
| Whether this executor runs one task at a time, each after the tasks posted before it: a strand, a GUI loop, a pumped MainThreadExecutor. | |
| ::core::async::IExecutor & | coreExecutor () noexcept |
| This executor as a core-cpp executor: the identity an core::async::ExecutorScope names. | |
One strand over a morph executor, usable wherever a morph executor is: the owner a component's state belongs to.
Tasks run one at a time, in the order they were posted, on the threads of the base executor. A component keeps its state in tasks on one of these and needs no lock for it: RemoteServer keeps its registry here, and ReconnectCoordinator its reconnect sequence.
Every task runs inside an ExecutorScope naming this object's coreExecutor(), so inside a task runningOn(*this) is true — as is runningOn(base), whose scope the strand's batch runs within — and a coroutine that suspends in a task and resumes on the current executor comes back here. Outside every task both are false.
Being a morph::exec::IExecutor is what lets a component hand its owner out as a Completion's callback executor, or to a collaborator that must run on the same owner (SyncWorker, on the coordinator's strand).
Definition at line 39 of file owner_strand.hpp.
|
inlineexplicit |
| base | Where the strand's tasks run. Borrowed: it must outlive this object and keep running tasks until it is closed. |
Definition at line 43 of file owner_strand.hpp.
|
inlineoverride |
Closes the strand: what is still queued is dropped, and a task running on another thread is waited for.
Definition at line 54 of file owner_strand.hpp.
|
inlineoverridevirtual |
Queues task after everything posted before it. A throw out of it is logged. Dropped once the strand is closed.
| task | Callable to run on the strand. |
Implements morph::exec::IExecutor.
Definition at line 59 of file owner_strand.hpp.
|
inline |
Queues task, held by value in the strand's one allocation for it, after everything posted before it. A throw out of it is logged. Dropped once the strand is closed.
What a component posts to its own strand: no std::function in between, so a move-only capture is fine and a post costs one allocation.
| F | The callable's type. |
| task | Callable to run on the strand. |
Definition at line 72 of file owner_strand.hpp.
|
inlinenodiscardnoexcept |
Whether the calling thread is inside one of this strand's tasks.
Definition at line 78 of file owner_strand.hpp.
|
inlinenodiscard |
Whether nothing is queued or running.
Definition at line 82 of file owner_strand.hpp.
|
inline |
Closes the strand, as the destructor does. Idempotent.
Definition at line 85 of file owner_strand.hpp.
|
inline |
Refuses the strand's try-forms and keeps running what is queued; post is still admitted until close(). Idempotent.
Definition at line 89 of file owner_strand.hpp.