morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::exec::OwnerStrand Class Referencefinal

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>

Inheritance diagram for morph::exec::OwnerStrand:
morph::exec::IExecutor

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ OwnerStrand()

morph::exec::OwnerStrand::OwnerStrand ( ::morph::exec::IExecutor & base)
inlineexplicit
Parameters
baseWhere 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.

◆ ~OwnerStrand()

morph::exec::OwnerStrand::~OwnerStrand ( )
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.

Member Function Documentation

◆ post()

void morph::exec::OwnerStrand::post ( std::function< void()> task)
inlineoverridevirtual

Queues task after everything posted before it. A throw out of it is logged. Dropped once the strand is closed.

Parameters
taskCallable to run on the strand.

Implements morph::exec::IExecutor.

Definition at line 59 of file owner_strand.hpp.

◆ postTask()

template<typename F>
void morph::exec::OwnerStrand::postTask ( F && task)
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.

Template Parameters
FThe callable's type.
Parameters
taskCallable to run on the strand.

Definition at line 72 of file owner_strand.hpp.

◆ runningHere()

bool morph::exec::OwnerStrand::runningHere ( ) const
inlinenodiscardnoexcept

Whether the calling thread is inside one of this strand's tasks.

Returns
True inside a task, at any depth.

Definition at line 78 of file owner_strand.hpp.

◆ idle()

bool morph::exec::OwnerStrand::idle ( ) const
inlinenodiscard

Whether nothing is queued or running.

Returns
True when idle. Racy by nature where other threads post.

Definition at line 82 of file owner_strand.hpp.

◆ close()

void morph::exec::OwnerStrand::close ( )
inline

Closes the strand, as the destructor does. Idempotent.

Definition at line 85 of file owner_strand.hpp.

◆ seal()

void morph::exec::OwnerStrand::seal ( )
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.


The documentation for this class was generated from the following file: