Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::BackgroundWorkerStorage Class Reference

Optional executor capability for bounded opaque worker-owned caches. Direct operations borrow the live executor. Leases retain only separate light controls. Payload callbacks run synchronously only inside this executor's BackgroundJob::run extent. They must not retain a borrowed value/build scope, UI state, or coroutine storage. More...

#include <worker_storage.hpp>

Public Member Functions

 ~BackgroundWorkerStorage ()
 Final host teardown after all workers join, never scene retirement.
 BackgroundWorkerStorage (const BackgroundWorkerStorage &)=delete
BackgroundWorkerStorage & operator= (const BackgroundWorkerStorage &)=delete
std::expected< WorkerStorageLease, BackgroundError > registerSlot ()
std::uint64_t changeEpoch () const noexcept
WorkerStorageStats stats () const noexcept
std::expected< void, BackgroundError > withRead (WorkerStorageId id, const std::function< std::expected< void, BackgroundError >(const WorkerStorageValue &)> &read)
std::expected< void, BackgroundError > withBuild (WorkerStorageId id, std::size_t residentCap, std::size_t scratchCap, const std::function< std::expected< void, BackgroundError >(WorkerStorageBuild &)> &build)

Friends

class BackgroundPool

Detailed Description

Optional executor capability for bounded opaque worker-owned caches. Direct operations borrow the live executor. Leases retain only separate light controls. Payload callbacks run synchronously only inside this executor's BackgroundJob::run extent. They must not retain a borrowed value/build scope, UI state, or coroutine storage.

Member Function Documentation

◆ changeEpoch()

std::uint64_t portals::BackgroundWorkerStorage::changeEpoch ( ) const
noexcept
Returns
Advisory readiness generation; sample before admission to avoid missed release.

◆ registerSlot()

std::expected< WorkerStorageLease, BackgroundError > portals::BackgroundWorkerStorage::registerSlot ( )
Returns
Light slot registration or explicit CLOSED/WOULD_BLOCK/NO_MEMORY.

◆ stats()

WorkerStorageStats portals::BackgroundWorkerStorage::stats ( ) const
noexcept
Returns
Current allocation-capacity accounting, safe while host lives.

◆ withBuild()

std::expected< void, BackgroundError > portals::BackgroundWorkerStorage::withBuild ( WorkerStorageId id,
std::size_t residentCap,
std::size_t scratchCap,
const std::function< std::expected< void, BackgroundError >(WorkerStorageBuild &)> & build )
Parameters
idExact registration; build excludes readers and another build on this slot.
residentCapReserved resident bytes, including transient reallocation peak.
scratchCapReserved temporary bytes, released only after callback returns.
buildWorker callback allocating within both reservations and committing once.
Returns
Original callback result, LIMIT_EXCEEDED for an impossible own request, or bounded backpressure. Idle LRU values can be reclaimed on this worker before admission. No worker waits for other work.

◆ withRead()

std::expected< void, BackgroundError > portals::BackgroundWorkerStorage::withRead ( WorkerStorageId id,
const std::function< std::expected< void, BackgroundError >(const WorkerStorageValue &)> & read )
Parameters
idRegistration identity from this executor.
readWorker callback borrowing an immutable opaque payload for this invocation only.
Returns
Original callback result or WRONG_THREAD/CLOSED/WOULD_BLOCK; exceptions translated.

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