5#include <portals/background_options.hpp>
14struct WorkerStorageControl;
15struct WorkerStorageWake;
49 friend class BackgroundWorkerStorage;
51 : id_(
id), control_(std::move(control)) {}
53 std::weak_ptr<detail::WorkerStorageControl> control_;
57class WorkerStorageBuild {
59 WorkerStorageBuild(
const WorkerStorageBuild &) =
delete;
60 WorkerStorageBuild &operator=(
const WorkerStorageBuild &) =
delete;
61 WorkerStorageBuild(WorkerStorageBuild &&) =
delete;
62 WorkerStorageBuild &operator=(WorkerStorageBuild &&) =
delete;
68 std::expected<void, BackgroundError>
commit(std::unique_ptr<WorkerStorageValue> &value, std::size_t bytes);
70 std::size_t
residentCap() const noexcept {
return residentCap_; }
72 std::size_t
scratchCap() const noexcept {
return scratchCap_; }
76 WorkerStorageBuild(std::size_t resident, std::size_t scratch) : residentCap_(resident), scratchCap_(scratch) {}
77 std::size_t residentCap_{}, scratchCap_{}, bytes_{};
78 std::unique_ptr<WorkerStorageValue> value_;
94class BackgroundWorkerStorage {
97 BackgroundWorkerStorage(
const BackgroundWorkerStorage &) =
delete;
98 BackgroundWorkerStorage &operator=(
const BackgroundWorkerStorage &) =
delete;
123 friend class BackgroundPool;
125 BackgroundWorkerStorage(std::
size_t slots, std::
size_t bytes, std::shared_ptr<detail::WorkerStorageWake> wake);
126 void execute(
void *context,
void (*run)(
void *) noexcept) noexcept;
127 void drain() noexcept;
128 bool retirementPending() const noexcept;
129 void close() noexcept;
130 std::unique_ptr<State> state_;
Optional executor capability for bounded opaque worker-owned caches. Direct operations borrow the liv...
Definition worker_storage.hpp:94
std::expected< void, BackgroundError > withBuild(WorkerStorageId id, std::size_t residentCap, std::size_t scratchCap, const std::function< std::expected< void, BackgroundError >(WorkerStorageBuild &)> &build)
std::uint64_t changeEpoch() const noexcept
std::expected< void, BackgroundError > withRead(WorkerStorageId id, const std::function< std::expected< void, BackgroundError >(const WorkerStorageValue &)> &read)
WorkerStorageStats stats() const noexcept
std::expected< WorkerStorageLease, BackgroundError > registerSlot()
~BackgroundWorkerStorage()
Final host teardown after all workers join, never scene retirement.
Nonmovable build scope, valid only inside withBuild's worker callback.
Definition worker_storage.hpp:57
std::size_t scratchCap() const noexcept
Definition worker_storage.hpp:72
std::size_t residentCap() const noexcept
Definition worker_storage.hpp:70
std::expected< void, BackgroundError > commit(std::unique_ptr< WorkerStorageValue > &value, std::size_t bytes)
WorkerStorageLease(WorkerStorageLease &&) noexcept
Transfer retirement ownership.
~WorkerStorageLease()
Idempotent retirement; no allocation, traversal, join or payload destruction.
void retire() noexcept
Mark retired and notify separate light wake storage; safe after host destruction.
WorkerStorageLease()=default
Empty lease.
Opaque worker-owned payload. Destruction must be worker-safe and nonthrowing.
Definition worker_storage.hpp:19
virtual ~WorkerStorageValue()=default
Released on a worker or final post-UI host teardown.
Public Portals API.
Definition action.hpp:8
BackgroundError
Executor admission and startup failures; domain errors stay in the result value.
Definition background_options.hpp:11
Generation-fenced slot identity; carries no payload ownership.
Definition worker_storage.hpp:25
std::uint64_t value
One-based slot number.
Definition worker_storage.hpp:26
bool operator==(const WorkerStorageId &) const noexcept=default
std::uint64_t generation
Nonzero registration generation, never reused.
Definition worker_storage.hpp:27
Allocation-capacity observations, distinct from process RSS.
Definition worker_storage.hpp:82
std::size_t peakBytes
High-water charged bytes; never exceeds aggregate limit.
Definition worker_storage.hpp:84
std::uint64_t evictions
Idle cache values evicted under pressure.
Definition worker_storage.hpp:86
std::size_t slots
Registered plus retiring slots.
Definition worker_storage.hpp:85
std::size_t chargedBytes
Resident, detached reclaiming, and full active build reservations.
Definition worker_storage.hpp:83