boost::capy::executor_ref

Forwards dispatch/`post`/`context` calls through a non‐owning, type‐erased executor pointer.

Synopsis

class executor_ref;

Description

This class provides type erasure for any executor type, enabling runtime polymorphism without virtual functions or allocation. It stores a pointer to the original executor and a pointer to a static vtable. Executors of different types are therefore stored uniformly, while satisfying the full Executor concept.

Reference Semantics

This class has reference semantics: it does not allocate or own the wrapped executor. Copy operations copy the internal pointers. The caller must ensure the referenced executor outlives all executor_ref instances that wrap it.

Thread Safety

The executor_ref itself is not thread‐safe for concurrent modification, but its executor operations are safe to call concurrently if the underlying executor supports it.

Executor Concept

This class satisfies the Executor concept, making it usable anywhere a concrete executor is expected.

Example

// my_continuation must stay at a stable address until the executor
// dequeues it, so it is owned by the caller, not by store_executor().
void store_executor(capy::executor_ref ex, capy::continuation& my_continuation)
{
    if(ex)
        ex.post(my_continuation);
}

void use_thread_pool(capy::thread_pool& ctx, capy::continuation& my_continuation)
{
    store_executor(ctx.get_executor(), my_continuation);
}

Member Functions

Name

Description

executor_ref [constructor]

Constructors

operator=

Copy assignment operator.

context

Returns a reference to the associated execution context.

dispatch

Dispatches a continuation through the wrapped executor.

on_work_finished

Informs the executor that work has completed.

on_work_started

Informs the executor that work is beginning.

post

Posts a continuation to the wrapped executor.

target

Return a pointer to the wrapped executor if it matches the requested type.

operator bool

Returns true if this instance holds a valid executor.

operator==

Compares two executor references for equality.

See Also

Created with MrDocs