StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Buffer::ByteBudget Class Reference

Shared logical byte accounting for queues and concurrent work. More...

#include <StormByte/buffer/byte_budget.hxx>

Classes

class  Lease
 Shared charge that can explicitly follow one payload across queues or work. More...

Public Member Functions

 ByteBudget ()
 Construct an unlimited aggregate budget.
STORMBYTE_FORCE_INLINE ByteBudget (std::nullopt_t)
 Explicitly construct an unlimited budget.
 ByteBudget (StormByte::ByteSize limit)
 Construct a fixed aggregate ceiling; zero allows only zero-byte charges.
 ByteBudget (const ByteBudget &other) noexcept=default
 Share budget identity and counters.
 ByteBudget (ByteBudget &&other) noexcept=default
 Transfer a budget handle.
 ~ByteBudget () noexcept=default
 Release this handle without closing other handles or leases.
ByteBudget & operator= (const ByteBudget &other) noexcept=default
 Share another budget.
ByteBudget & operator= (ByteBudget &&other) noexcept=default
 Transfer another budget handle.
QueueStatus TryReserve (StormByte::ByteSize bytes, Lease &output) const noexcept
 Reserve without waiting for capacity.
STORMBYTE_FORCE_INLINE QueueStatus ReserveFor (StormByte::ByteSize bytes, Lease &output, std::chrono::milliseconds timeout) const noexcept
 Reserve with a bounded wait; zero attempts immediately.
void Close () const noexcept
 Reject future reservations and wake waiters, retaining existing charges.
void CancelPending () const noexcept
 Cancel currently waiting admissions without closing or invalidating leases.
bool SharesIdentity (const ByteBudget &other) const noexcept
 Compare shared provider state without reserving or locking.
BudgetSnapshot Snapshot () const noexcept
 Read counters under a short state lock, without capacity waits or I/O.

Friends

struct Detail::BudgetAccess

Detailed Description

Shared logical byte accounting for queues and concurrent work.

Copies share provider-owned state. A lease is charged once until its final copy is released. Buffer and Base must remain loaded. Independent handles may be used concurrently; do not move/assign a handle in use.

Constructor & Destructor Documentation

◆ ByteBudget() [1/5]

StormByte::Buffer::ByteBudget::ByteBudget ( )
inline

Construct an unlimited aggregate budget.

◆ ByteBudget() [2/5]

STORMBYTE_FORCE_INLINE StormByte::Buffer::ByteBudget::ByteBudget ( std::nullopt_t )
inlineexplicit

Explicitly construct an unlimited budget.

◆ ByteBudget() [3/5]

StormByte::Buffer::ByteBudget::ByteBudget ( StormByte::ByteSize limit)
inlineexplicit

Construct a fixed aggregate ceiling; zero allows only zero-byte charges.

Parameters
limitAggregate logical bytes.

◆ ByteBudget() [4/5]

StormByte::Buffer::ByteBudget::ByteBudget ( const ByteBudget & other)
defaultnoexcept

Share budget identity and counters.

Parameters
otherSource budget.

◆ ByteBudget() [5/5]

StormByte::Buffer::ByteBudget::ByteBudget ( ByteBudget && other)
defaultnoexcept

Transfer a budget handle.

Parameters
otherSource, left invalid.

◆ ~ByteBudget()

StormByte::Buffer::ByteBudget::~ByteBudget ( )
defaultnoexcept

Release this handle without closing other handles or leases.

Member Function Documentation

◆ CancelPending()

void StormByte::Buffer::ByteBudget::CancelPending ( ) const
noexcept

Cancel currently waiting admissions without closing or invalidating leases.

◆ Close()

void StormByte::Buffer::ByteBudget::Close ( ) const
noexcept

Reject future reservations and wake waiters, retaining existing charges.

◆ operator=() [1/2]

ByteBudget & StormByte::Buffer::ByteBudget::operator= ( ByteBudget && other)
defaultnoexcept

Transfer another budget handle.

Parameters
otherSource, left invalid.
Returns
This handle.

◆ operator=() [2/2]

ByteBudget & StormByte::Buffer::ByteBudget::operator= ( const ByteBudget & other)
defaultnoexcept

Share another budget.

Parameters
otherSource budget.
Returns
This handle.

◆ ReserveFor()

STORMBYTE_FORCE_INLINE QueueStatus StormByte::Buffer::ByteBudget::ReserveFor ( StormByte::ByteSize bytes,
Lease & output,
std::chrono::milliseconds timeout ) const
inlinenoexcept

Reserve with a bounded wait; zero attempts immediately.

Parameters
bytesCaller-defined weight.
outputReplaced only on success.
timeoutNonnegative wait duration.
Returns
Admission result; oversize weights fail without waiting.

◆ SharesIdentity()

bool StormByte::Buffer::ByteBudget::SharesIdentity ( const ByteBudget & other) const
noexcept

Compare shared provider state without reserving or locking.

Works before and after Close. Independent budgets differ even with equal limits and counters; moved-from handles share nothing, even together. Concurrent comparison is safe unless a handle is moved or assigned.

Parameters
otherCandidate handle.
Returns
True when both valid handles share one internal state.

◆ Snapshot()

BudgetSnapshot StormByte::Buffer::ByteBudget::Snapshot ( ) const
noexcept

Read counters under a short state lock, without capacity waits or I/O.

Returns
Coherent aggregate accounting.

◆ TryReserve()

QueueStatus StormByte::Buffer::ByteBudget::TryReserve ( StormByte::ByteSize bytes,
Lease & output ) const
noexcept

Reserve without waiting for capacity.

Parameters
bytesCaller-defined weight.
outputReplaced only on success.
Returns
Explicit admission result; allocation failure rolls back the charge.

◆ Detail::BudgetAccess

friend struct Detail::BudgetAccess
friend

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