Idris2Doc : Data.Pool.Internal

Data.Pool.Internal

(source)
Resource Pool Internals

Definitions

recordPoolConfig : Type->Type
  Configuration of a Pool.

Constraints:
- poolmaxresources -> The smallest acceptable value is 1.
- poolnumstripes -> The smallest acceptable value is 1, poolnumstripes must not be larger than poolmaxresources.

Totality: total
Visibility: public export
Constructor: 
MkPoolConfig : IOa-> (a->IO ()) ->ClockDuration-> (poolmaxresources : (maxres : Nat**LTE1maxres)) -> (n : Nat** (LTE1n, LTEn (fstpoolmaxresources))) ->String->PoolConfiga

Projections:
.createresource : PoolConfiga->IOa
.freeresource : PoolConfiga->a->IO ()
.poolcachettl : PoolConfiga->ClockDuration
.poolconfiglabel : PoolConfiga->String
.poolmaxresources : PoolConfiga-> (maxres : Nat**LTE1maxres)
.poolnumstripes : ({rec:0} : PoolConfiga) -> (n : Nat** (LTE1n, LTEn (fst (poolmaxresources{rec:0}))))
.createresource : PoolConfiga->IOa
Totality: total
Visibility: public export
createresource : PoolConfiga->IOa
Totality: total
Visibility: public export
.freeresource : PoolConfiga->a->IO ()
Totality: total
Visibility: public export
freeresource : PoolConfiga->a->IO ()
Totality: total
Visibility: public export
.poolcachettl : PoolConfiga->ClockDuration
Totality: total
Visibility: public export
poolcachettl : PoolConfiga->ClockDuration
Totality: total
Visibility: public export
.poolmaxresources : PoolConfiga-> (maxres : Nat**LTE1maxres)
Totality: total
Visibility: public export
poolmaxresources : PoolConfiga-> (maxres : Nat**LTE1maxres)
Totality: total
Visibility: public export
.poolnumstripes : ({rec:0} : PoolConfiga) -> (n : Nat** (LTE1n, LTEn (fst (poolmaxresources{rec:0}))))
Totality: total
Visibility: public export
poolnumstripes : ({rec:0} : PoolConfiga) -> (n : Nat** (LTE1n, LTEn (fst (poolmaxresources{rec:0}))))
Totality: total
Visibility: public export
.poolconfiglabel : PoolConfiga->String
Totality: total
Visibility: public export
poolconfiglabel : PoolConfiga->String
Totality: total
Visibility: public export
dataQueue : Type->Type
  A simple (persistent) FIFO queue.

This is used to maintain an ordered collection of waiting threads.
Elements are appended at the tail and removed from the head.

Notes:
- This representation has O(n) append.
- Under contention (with CAS updates), appends may be retried, so this structure favors simplicity over performance.
- It is typically used together with a secondary "reversed" queue to amortize costs (two-list queue pattern).

Totality: total
Visibility: public export
Constructors:
QNode : a->Queuea->Queuea
QEnd : Queuea
dataWakeResult : Type->Type
  Result of waking a waiting thread.

This represents the outcome delivered to a blocked waiter through its wake channel.

Variants:
- `Deliver a`
- A resource was directly handed off to the waiter.

- `Create`
- No reusable resource was available, but the waiter should proceed by creating a fresh resource using an already-reserved capacity slot.

- `Cancelled`
- The waiter was cancelled before receiving a resource.
- This is used to distinguish cancellation from normal wakeup semantics.

Design Notes:
- This replaces the older `Maybe a` wake protocol, which overloaded `Nothing` to represent multiple meanings.
- Explicit wake states improve clarity and correctness of the Stripe state machine.

Guarantees:
- Each waiter receives at most one `WakeResult`.
- Wake results correspond only to committed Stripe transitions.
- No wake result is delivered more than once.

Invariants:
- `Deliver a` carries ownership transfer of exactly one resource.
- `Create` implies capacity has already been reserved.
- `Cancelled` does not transfer ownership of a resource.

Totality: total
Visibility: public export
Constructors:
Deliver : a->WakeResulta
Create : WakeResulta
Cancelled : WakeResulta
dataWaiter : Type->Type
  A pure waiting token representing a blocked thread.

This contains no mutable state. All lifecycle tracking is handled
by the Stripe during dequeue / cancellation.

Fields:
- `id` : unique identifier for cancellation tracking
- `wake` : channel used to unblock the thread

Invariants:
- Waiter is immutable
- Wake is single-use
- Cancellation is handled by Stripe (not locally)

Totality: total
Visibility: public export
Constructor: 
MkWaiter : Nat->Channel (WakeResulta) ->Waitera
dataEntry : Type->Type
  An existing resource currently sitting in a pool.

Totality: total
Visibility: public export
Constructor: 
MkEntry : a->IClockCLOCK_MONOTONIC->Entrya
dataStripe : Type->Type
  Stripe is the only concurrent state machine in the system.

It owns:
- Resource availability.
- Cached resources.
- All waiting threads.
- Cancellation tracking.

All mutations occur via CAS on an enclosing Ref, `Stripe1 s a`.

Fields:
- `available` : number of available resources
- `cache` : reusable resources
- `queue` : primary FIFO of waiters
- `queuer` : secondary FIFO (amortized append)
- `nextId` : fresh waiter id supply
- `cancelled` : sorted set of cancelled waiter ids

Invariants:
- Stripe is immutable between CAS updates.
- Queue ordering is authoritative.
- Cancelled waiters are lazily skipped.

Totality: total
Visibility: public export
Constructor: 
MkStripe : Nat->List (Entrya) ->Queue (Waitera) ->Queue (Waitera) ->Nat->SortedSetNat->Stripea
dataStripe1 : Type->Type->Type
  A linear mutable stripe.

Totality: total
Visibility: public export
Constructor: 
MkStripe1 : Refs (Stripea) ->Stripe1sa
dataStripeEffect : Type->Type
  Effects emitted by a Stripe transition.

These are collected during CAS computation and executed
only after a successful CAS commit.

Guarantees:
- No IO inside CAS.
- No duplicated effects on retry.
- Deterministic state transitions.

Totality: total
Visibility: public export
Constructors:
Wake : Channel (WakeResulta) ->WakeResulta->StripeEffecta
WakeMany : List (Channel (WakeResulta), WakeResulta) ->StripeEffecta
InsertWithTimestamp : a->StripeEffecta
FreeMany : (a->IO ()) ->Lista->StripeEffecta
None : StripeEffecta
recordStripeStep : Type->Type
  Result of a Stripe state transition.

Represents:
- The new Stripe state (to be CAS'd).
- Effects to run AFTER successful commit.

Invariants:
- This must be treated as a one-shot value.
- If CAS fails, this MUST be discarded.
- Effects must NEVER be run unless CAS succeeds.

Totality: total
Visibility: public export
Constructor: 
MkStripeStep : Stripea->List (StripeEffecta) ->StripeStepa

Projections:
.effects : StripeStepa->List (StripeEffecta)
.stripe : StripeStepa->Stripea
.stripe : StripeStepa->Stripea
Totality: total
Visibility: public export
stripe : StripeStepa->Stripea
Totality: total
Visibility: public export
.effects : StripeStepa->List (StripeEffecta)
Totality: total
Visibility: public export
effects : StripeStepa->List (StripeEffecta)
Totality: total
Visibility: public export
dataLocalPool1 : Type->Type->Type
  A single, local pool based on a linear mutable stripe.

Totality: total
Visibility: public export
Constructor: 
MkLocalPool1 : Nat->Stripe1sa->LocalPool1sa
dataPool1 : Type->Nat->Type->Type
  Striped resource pool based on linear mutable references.

Totality: total
Visibility: public export
Constructor: 
MkPool1 : PoolConfiga->MArraysn (LocalPool1sa) ->Pool1sna