ecor
Loading...
Searching...
No Matches
ecor::async_arena< Ctx, Mem > Struct Template Reference

Async arena. More...

#include <ecor.hpp>

Public Member Functions

 async_arena (async_arena &&)=delete
 
 async_arena (async_arena const &)=delete
 
 async_arena (Ctx &ctx, Mem &mem) noexcept
 Construct an async arena with the provided context and memory resource.
 
_ll_sender< set_value_t() > async_destroy () noexcept
 Signal that no new objects will be created and return a sender that completes with set_value_t() when all pending async destructions have finished.
 
template<typename T , typename... Args>
async_ptr< T, Ctx, Mem > make (Args &&... args)
 Create a new managed object of type T. More...
 
async_arenaoperator= (async_arena &&)=delete
 
async_arenaoperator= (async_arena const &)=delete
 

Detailed Description

template<typename Ctx, typename Mem>
struct ecor::async_arena< Ctx, Mem >

Async arena.

Creates async_ptr instances and provides graceful shutdown via async_destroy(). This allows construction of datasets of type with asynchronous destruction requirements, and ensures that all pending destructions complete before shutdown.

For any type managed by the arena, we assume that async_destroy CPO can be used and guaranteee that it's get called before standard destructor of the object.

Arena uses reference-counted pointers to handle lifetime of the objects. When the last async_ptr to an object is destroyed, the arena initiates asynchronous destruction of the object by enqueuing it for cleanup in provided task context object. The arena keeps track of all alive objects and pending destructions, and provides a sender that completes when all pending destructions have finished after shutdown is initiated.

Any memory is allocated via Mem memory resource provided to the arena. Arena allocates newly created objects and all internal bookkeeping structures (control blocks, destroy operations) from the provided memory resource, and deallocates them when they are destroyed.

The resulting operation state from sender returned by objects async_destroy() is stored in memory blocked allocated from the arena's memory resource, and is properly destroyed and deallocated when the destruction completes.

The arena itself is not thread-safe and must be used from a single task context.

Precondition: async_destroy() sender must complete before the arena is destroyed.

Member Function Documentation

◆ make()

template<typename Ctx , typename Mem >
template<typename T , typename... Args>
async_ptr< T, Ctx, Mem > ecor::async_arena< Ctx, Mem >::make ( Args &&...  args)
inline

Create a new managed object of type T.

Returns an async_ptr<T,Ctx,Mem> with a reference count of 1. Returns a null async_ptr if allocation fails.


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