45#include <StormByte/byte_size.hxx>
46#include <StormByte/safe/optional.hxx>
47#include <StormByte/safe/pointers.hxx>
48#include <StormByte/size.hxx>
49#include <StormByte/type_traits/safe.hxx>
135 m_elements_limited(elements.has_value()),
136 m_bytes_limited(bytes.has_value()),
181 constexpr bool BytesLimited() const noexcept {
return m_bytes_limited; }
194 m_elements = elements;
195 m_elements_limited =
true;
202 m_elements_limited =
false;
213 bool m_elements_limited;
214 bool m_bytes_limited;
303 explicit operator
bool() const noexcept;
397 std::chrono::milliseconds timeout) const noexcept {
398 return ReserveMilliseconds(bytes, output, timeout.count());
440 std::size_t Revision;
441 std::size_t Cancellation;
455 Event CurrentEvent() const noexcept;
460 void Notify() const noexcept;
467 void Wait(Event event,
std::int64_t nanoseconds) const noexcept;
477 std::int64_t milliseconds) const noexcept;
496 static auto Event(
const ByteBudget& budget)
noexcept {
return budget.CurrentEvent(); }
511 std::int64_t nanoseconds)
noexcept {
512 budget.Wait(event, nanoseconds);
Shared charge that can explicitly follow one payload across queues or work.
Definition byte_budget.hxx:261
StormByte::ByteSize Bytes() const noexcept
Size reserved once for all copies.
bool BelongsTo(const ByteBudget &budget) const noexcept
Check shared budget identity.
friend class ByteBudget
Definition byte_budget.hxx:324
void Reset() noexcept
Release this reference.
Lease() noexcept=default
Construct an empty charge.
Shared logical byte accounting for queues and concurrent work.
Definition byte_budget.hxx:256
bool SharesIdentity(const ByteBudget &other) const noexcept
Compare shared provider state without reserving or locking.
void Close() const noexcept
Reject future reservations and wake waiters, retaining existing charges.
QueueStatus TryReserve(StormByte::ByteSize bytes, Lease &output) const noexcept
Reserve without waiting for capacity.
~ByteBudget() noexcept=default
Release this handle without closing other handles or leases.
STORMBYTE_FORCE_INLINE QueueStatus ReserveFor(StormByte::ByteSize bytes, Lease &output, std::chrono::milliseconds timeout) const noexcept
Reserve with a bounded wait; zero attempts immediately.
Definition byte_budget.hxx:396
STORMBYTE_FORCE_INLINE ByteBudget(std::nullopt_t)
Explicitly construct an unlimited budget.
Definition byte_budget.hxx:342
ByteBudget()
Construct an unlimited aggregate budget.
Definition byte_budget.hxx:337
BudgetSnapshot Snapshot() const noexcept
Read counters under a short state lock, without capacity waits or I/O.
void CancelPending() const noexcept
Cancel currently waiting admissions without closing or invalidating leases.
ByteBudget(const ByteBudget &other) noexcept=default
Share budget identity and counters.
friend struct Detail::BudgetAccess
Definition byte_budget.hxx:429
ByteBudget(ByteBudget &&other) noexcept=default
Transfer a budget handle.
ByteBudget(StormByte::ByteSize limit)
Construct a fixed aggregate ceiling; zero allows only zero-byte charges.
Definition byte_budget.hxx:348
General exception for buffer errors.
Definition exception.hxx:166
Independent local bounds; absent means unlimited, engaged zero means zero capacity.
Definition byte_budget.hxx:125
QueueLimits(QueueLimits &&other) noexcept=default
Move resolved bounds without ownership.
constexpr StormByte::ByteSize Bytes() const noexcept
Configured byte ceiling.
Definition byte_budget.hxx:210
constexpr StormByte::Size Elements() const noexcept
Configured item ceiling.
Definition byte_budget.hxx:187
constexpr bool BytesLimited() const noexcept
Whether a byte ceiling is configured.
Definition byte_budget.hxx:181
constexpr void Elements(StormByte::Size elements) noexcept
Engage an item ceiling without allocating an optional.
Definition byte_budget.hxx:193
~QueueLimits() noexcept=default
Destroy non-owning bounds.
QueueLimits(const QueueLimits &other) noexcept=default
Copy resolved bounds without allocation.
STORMBYTE_FORCE_INLINE QueueLimits(StormByte::Safe::Optional< StormByte::Size > elements={}, StormByte::Safe::Optional< StormByte::ByteSize > bytes={}) noexcept
Resolve optional limits into a non-owning value.
Definition byte_budget.hxx:132
constexpr bool ElementsLimited() const noexcept
Whether an item ceiling is configured.
Definition byte_budget.hxx:175
constexpr void UnlimitedElements() noexcept
Remove only the item ceiling without changing byte limits.
Definition byte_budget.hxx:201
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffer module of the StormByte suite.
QueueStatus
Admission outcomes.
Definition byte_budget.hxx:80
@ Closed
Queue, Sink or budget closed.
Definition byte_budget.hxx:84
@ Missing
Sink key does not exist.
Definition byte_budget.hxx:87
@ Invalid
Invalid duration, lease or configuration.
Definition byte_budget.hxx:90
@ TooLarge
The item can never fit the configured limit.
Definition byte_budget.hxx:83
@ Cancelled
Pending admissions cancelled.
Definition byte_budget.hxx:85
@ Ok
Accepted.
Definition byte_budget.hxx:81
@ Timeout
Bounded wait expired.
Definition byte_budget.hxx:86
@ Empty
Nullable item was empty.
Definition byte_budget.hxx:88
@ WouldBlock
Capacity unavailable.
Definition byte_budget.hxx:82
AdmissionWaitReason
Cause of a weighted admission wait, selected while admission is locked.
Definition byte_budget.hxx:96
@ LocalCapacity
Local element or byte bounds deny admission before reservation.
Definition byte_budget.hxx:97
@ SharedBudget
Local bounds allow admission but TryReserve reports WouldBlock.
Definition byte_budget.hxx:98
Root namespace of the StormByte C++ suite.
Borrowed, allocation-free observer for one synchronous PushFor call.
Definition byte_budget.hxx:117
void(* Changed)(void *, AdmissionWaitReason, bool entering) noexcept
Wait transition.
Definition byte_budget.hxx:119
void * Context
Borrowed callback context.
Definition byte_budget.hxx:118
Shared reservation counters, independent of any particular queue.
Definition byte_budget.hxx:238
std::size_t Pressure
Reservations refused for temporary capacity pressure.
Definition byte_budget.hxx:243
std::size_t Waits
ReserveFor calls that actually waited.
Definition byte_budget.hxx:244
std::int64_t WaitNanoseconds
Accumulated ReserveFor wait duration.
Definition byte_budget.hxx:245
StormByte::ByteSize Limit
Configured aggregate ceiling.
Definition byte_budget.hxx:240
bool Limited
Aggregate ceiling is active.
Definition byte_budget.hxx:239
StormByte::ByteSize Reserved
Live lease charges, including work outside queues.
Definition byte_budget.hxx:241
bool Closed
Further reservations are forbidden.
Definition byte_budget.hxx:246
StormByte::ByteSize Peak
Lifetime peak reservations.
Definition byte_budget.hxx:242
Queue wake transport; never calls into queues under the budget mutex.
Definition byte_budget.hxx:490
static void Wait(const ByteBudget &budget, ByteBudget::Event event, std::int64_t nanoseconds) noexcept
Wait for state changes without holding queue locks.
Definition byte_budget.hxx:510
static void Notify(const ByteBudget &budget) noexcept
Publish a queue state change.
Definition byte_budget.hxx:502
static auto Event(const ByteBudget &budget) noexcept
Capture a stored event.
Definition byte_budget.hxx:496
Coherent queue accounting; bytes are caller-supplied weights, never RSS.
Definition byte_budget.hxx:222
std::size_t Waits
Admissions that actually waited.
Definition byte_budget.hxx:229
bool Closed
Production has ended.
Definition byte_budget.hxx:231
StormByte::ByteSize PeakBytes
Lifetime peak logical bytes.
Definition byte_budget.hxx:227
StormByte::ByteSize Bytes
Currently queued logical weights.
Definition byte_budget.hxx:225
bool Exists
False for a missing Sink key.
Definition byte_budget.hxx:232
QueueLimits Limits
Configured local bounds.
Definition byte_budget.hxx:223
std::size_t Pressure
Admissions encountering capacity pressure.
Definition byte_budget.hxx:228
std::int64_t WaitNanoseconds
Accumulated admission wait duration.
Definition byte_budget.hxx:230
StormByte::Size Elements
Currently queued entries.
Definition byte_budget.hxx:224
StormByte::Size PeakElements
Lifetime peak entries.
Definition byte_budget.hxx:226
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54