boost::capy::execution_context

Base class for I/O object containers providing service management.

Synopsis

class execution_context;

Description

An execution context represents a place where function objects are executed. It provides a service registry where polymorphic services can be stored and retrieved by type. Each service type may be stored at most once. Services may specify a nested key_type to enable lookup by a base class type.

Derived classes such as io_context extend this to provide execution facilities like event loops and thread pools. Derived class destructors must call shutdown() and destroy() to ensure proper service cleanup before member destruction.

Service Lifecycle

Services are created on first use via use_service() or explicitly via make_service(). During destruction, shutdown() is called on each service in reverse order of creation, then destroy() deletes them. Both functions are idempotent.

Thread Safety

Service registration and lookup functions are thread‐safe. The shutdown() and destroy() functions are not thread‐safe and must only be called during destruction.

Example

struct file_service : execution_context::service
{
protected:
    void shutdown() override {}
};

struct posix_file_service : file_service
{
    using key_type = file_service;

    explicit posix_file_service(execution_context&) {}
};

class io_context : public execution_context
{
public:
    ~io_context()
    {
        shutdown();
        destroy();
    }
};

io_context ctx;
ctx.make_service<posix_file_service>();
ctx.find_service<file_service>();       // returns posix_file_service*
ctx.find_service<posix_file_service>(); // also works

Types

Name

Description

service

Abstract base class for services owned by an execution context.

Member Functions

Name

Description

execution_context [constructor]

Default constructor.

~execution_context [destructor]

Destructor.

operator= [deleted]

Copy assignment operator

find_service

Return a pointer to the service of type T, or nullptr.

get_frame_allocator

Return the memory resource used for coroutine frame allocation.

has_service

Return true if a service of type T exists.

make_service

Construct and add a service.

set_frame_allocator

set_frame_allocator overloads

target

Return a pointer to this context if it matches the requested type.

use_service

Return a reference to the service of type T, creating it if needed.

Protected Member Functions

Name

Description

execution_context [constructor]

Construct from Derived

destroy

Destroy all services.

shutdown

Shut down all services.

Derived Classes

Name Description

thread_pool

A pool of threads for executing work concurrently.

See Also

service, is_execution_context

Created with MrDocs