boost::capy::execution_context
Base class for I/O object containers providing service management.
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
Member Functions
Name |
Description |
|
Default constructor. |
|
Destructor. |
|
Copy assignment operator |
Return a pointer to the service of type T, or nullptr. |
|
Return the memory resource used for coroutine frame allocation. |
|
Return true if a service of type T exists. |
|
Construct and add a service. |
|
|
|
Return a pointer to this context if it matches the requested type. |
|
Return a reference to the service of type T, creating it if needed. |
Protected Member Functions
Name |
Description |
|
Construct from |
Destroy all services. |
|
Shut down all services. |
See Also
service, is_execution_context
Created with MrDocs