9#include <memory_resource>
57template <
class T>
class Publisher;
60struct SourceCapacityState;
83 friend class SourceBudget;
85 std::shared_ptr<SourceBudget> root_;
113 friend class SourceBudget;
115 std::shared_ptr<detail::SourceCapacityState> state_;
119class SourceBudget : public std::enable_shared_from_this<SourceBudget> {
144 friend class SourceCredit;
145 friend class SourceCapacityObserver;
146 friend struct detail::SourceCapacityState;
147 std::shared_ptr<detail::SourceCapacityState> eligibleObserverLocked() noexcept;
148 void removeObserver(detail::SourceCapacityState &state) noexcept;
149 void disarmObserver(detail::SourceCapacityState &state) noexcept;
156 mutable std::mutex mutex_;
158 detail::SourceCapacityState *observers_{};
159 detail::SourceCapacityState *granted_{};
160 std::size_t observerCount_{};
161 std::uint64_t capacityEpoch_{};
168class SourceArena final :
public std::pmr::memory_resource {
176 std::size_t
used() const noexcept;
184 void *do_allocate(std::
size_t bytes, std::
size_t alignment) override;
185 void do_deallocate(
void *, std::
size_t, std::
size_t) override;
186 bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override;
188 std::unique_ptr<std::
byte[]> storage_;
189 std::
size_t capacity_{};
Copyable, worker-safe endpoint. It owns the closed channel state, never UI captures....
Definition scheduler.hpp:189
std::size_t used() const noexcept
static std::expected< std::shared_ptr< SourceArena >, SourceError > create(SourceCredit credit)
~SourceArena() override
Release backing before returning its credit.
static constexpr std::size_t METADATA_BYTES
Conservative per-allocation envelope for arena/control-block metadata.
Definition source_budget.hpp:180
std::size_t capacity() const noexcept
static constexpr std::size_t ROOT_METADATA_BYTES
Bootstrap ledger allowance, retained for the root lifetime.
Definition source_budget.hpp:121
static constexpr std::size_t CAPACITY_OBSERVER_BYTES
Precharged allowance for one capacity observer.
Definition source_budget.hpp:123
SourceBudgetUsage usage() const
std::expected< SourceCapacityObserver, SourceError > observeCapacity(Publisher< int > wake)
SourceBudgetOptions options() const noexcept
static std::expected< std::shared_ptr< SourceBudget >, SourceError > create(SourceBudgetOptions options={})
std::uint64_t capacityEpoch() const noexcept
std::expected< SourceCredit, SourceError > reserve(SourceBudgetUsage amount)
~SourceCapacityObserver()
Unregister without allocation or callbacks into UI.
SourceCapacityObserver & operator=(SourceCapacityObserver &&other) noexcept
std::expected< SourceCredit, SourceError > reserve(SourceBudgetUsage amount, SourceBudgetUsage peak)
bool takeReady() noexcept
void disarm() noexcept
Drop pending admission priority; no UI callback or worker join occurs.
std::expected< void, SourceError > arm(SourceBudgetUsage peak)
SourceCapacityObserver()=default
Empty observer; admission returns CLOSED.
SourceCapacityObserver(SourceCapacityObserver &&other) noexcept
Move-only credit; backing storage must be destroyed before this final credit owner.
Definition source_budget.hpp:64
SourceCredit(SourceCredit &&other) noexcept
std::expected< SourceCredit, SourceError > split(SourceBudgetUsage amount) noexcept
SourceCredit()=default
Empty credit.
SourceCredit & operator=(SourceCredit other) noexcept
SourceBudgetUsage usage() const noexcept
~SourceCredit()
Return the reservation to its root.
Public Portals API.
Definition action.hpp:8
@ CALLBACK_FAILED
A non-allocation exception escaped into a runner callback boundary.
Definition application.hpp:34
@ NO_MEMORY
Allocation failed at a runner exception boundary.
Definition application.hpp:33
@ CLOSED
Owner, node scope, scheduler or completion endpoint is closed.
Definition async.hpp:28
@ WRONG_THREAD
The operation or coroutine frame belongs to another thread.
Definition async.hpp:27
@ CANCELLED
Explicit cancellation or replacement stopped the invocation.
Definition async.hpp:29
@ WOULD_BLOCK
Active resume, invocation, registration or queue capacity rejects the operation.
Definition async.hpp:30
@ IDENTITY_EXHAUSTED
Invocation identity cannot advance without reuse.
Definition async.hpp:33
@ INVALID_ARGUMENT
Empty task, callback or immutable data owner, or invalid policy.
Definition async.hpp:26
@ UNSUPPORTED
The application explicitly excludes this annotated phase.
Definition key_binding.hpp:44
@ STALE_SOURCE
Result does not have the exact requested source revision.
Definition model_query.hpp:16
SourceError
Source protocol and admission failures, independent of a provider's storage format.
Definition source_budget.hpp:14
@ NO_PROGRESS
A MORE reply repeated its input gap.
Definition source_budget.hpp:32
@ IO_ERROR
Native source I/O failed; a typed adapter retains its per-operation cause.
Definition source_budget.hpp:37
@ INVALID_CURSOR
The provider cannot validate this opaque token.
Definition source_budget.hpp:25
@ CURSOR_CYCLE
A MORE reply repeated an earlier gap of this bounded fill.
Definition source_budget.hpp:33
@ CONTINUATION_LIMIT
Demand remains after four automatic page loads; partial pin is valid.
Definition source_budget.hpp:34
@ ROW_TOO_LARGE
One materialized row exceeds its inline/transitive byte limit.
Definition source_budget.hpp:29
@ INVALID_REPLY
Result shape, identities, revision or boundaries violate the protocol.
Definition source_budget.hpp:31
@ CONTEXT_ERROR
The tree rejected a stale/foreign context or invalidation.
Definition source_budget.hpp:22
@ REVISION_CHANGED
Requested provider revision is unavailable or a notification is stale.
Definition source_budget.hpp:26
@ POSITION_EXHAUSTED
Provider position representation cannot advance without wrapping.
Definition source_budget.hpp:27
@ PAGE_TOO_LARGE
The fixed page/workspace cannot hold the requested allocation.
Definition source_budget.hpp:30
@ ROW_NOT_FOUND
A supported stable-identity lookup did not find its row.
Definition source_budget.hpp:28
@ ALREADY_COMPLETED
This request generation already ran its single load.
Definition source_budget.hpp:36
Configurable root shared by typed pages, future text pages and replacement sessions.
Definition source_budget.hpp:49
std::size_t maxPages
Aggregate page allocations.
Definition source_budget.hpp:51
std::size_t maxWork
Aggregate work reservations.
Definition source_budget.hpp:52
std::size_t maxConsumers
Aggregate consumer reservations.
Definition source_budget.hpp:53
std::size_t maxBytes
Aggregate reserved capacity.
Definition source_budget.hpp:50
Simultaneous source reservations; bytes are requested capacities, not process RSS.
Definition source_budget.hpp:41
std::size_t work
Work owners, including cancelled but still live work.
Definition source_budget.hpp:44
std::size_t pages
Building, queued, cached and retained page allocations.
Definition source_budget.hpp:43
std::size_t bytes
Reserved bytes, including accounting allowances.
Definition source_budget.hpp:42
std::size_t consumers
Live consumer storage reservations.
Definition source_budget.hpp:45