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

Thread-safe credit ledger; final page/worker release may happen on any thread. More...

#include <source_budget.hpp>

Inheritance diagram for portals::SourceBudget:
portals::SourceBudgetportals::SourceBudget

Public Member Functions

std::expected< SourceCredit, SourceError > reserve (SourceBudgetUsage amount)
std::expected< SourceCapacityObserver, SourceError > observeCapacity (Publisher< int > wake)
std::uint64_t capacityEpoch () const noexcept
SourceBudgetUsage usage () const
SourceBudgetOptions options () const noexcept

Static Public Member Functions

static std::expected< std::shared_ptr< SourceBudget >, SourceError > create (SourceBudgetOptions options={})

Static Public Attributes

static constexpr std::size_t ROOT_METADATA_BYTES
 Bootstrap ledger allowance, retained for the root lifetime.
static constexpr std::size_t CAPACITY_OBSERVER_BYTES = 4096
 Precharged allowance for one capacity observer.

Friends

class SourceCredit
class SourceCapacityObserver
struct detail::SourceCapacityState

Detailed Description

Thread-safe credit ledger; final page/worker release may happen on any thread.

Member Function Documentation

◆ capacityEpoch()

std::uint64_t portals::SourceBudget::capacityEpoch ( ) const
noexcept
Returns
Advisory release generation; only capacity notifications, never byte identities, use this value.

◆ create()

std::expected< std::shared_ptr< SourceBudget >, SourceError > portals::SourceBudget::create ( SourceBudgetOptions options = {})
static
Parameters
optionsPositive capacity limits; includes a conservative bootstrap allowance.
Returns
New root or INVALID_ARGUMENT/NO_MEMORY.

◆ observeCapacity()

std::expected< SourceCapacityObserver, SourceError > portals::SourceBudget::observeCapacity ( Publisher< int > wake)
Parameters
wakeWorker-safe wake-only endpoint; no payload or UI callback is invoked by release.
Returns
Precharged4KiB RAII registration, bounded by maxConsumers, or a typed admission failure.

◆ options()

SourceBudgetOptions portals::SourceBudget::options ( ) const
noexcept
Returns
Immutable root limits.

◆ reserve()

std::expected< SourceCredit, SourceError > portals::SourceBudget::reserve ( SourceBudgetUsage amount)
Parameters
amountCapacities to reserve atomically before allocation or I/O.
Returns
Owning credit, or WOULD_BLOCK without changing any counter.

◆ usage()

SourceBudgetUsage portals::SourceBudget::usage ( ) const
Returns
One synchronized aggregate snapshot.

Member Data Documentation

◆ ROOT_METADATA_BYTES

std::size_t portals::SourceBudget::ROOT_METADATA_BYTES
staticconstexpr
Initial value:
=
4096

Bootstrap ledger allowance, retained for the root lifetime.


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