wireform-core-0.2.0.1: Shared FFI primitives for wireform format packages
Safe HaskellNone
LanguageGHC2021

Wireform.Ring.Pool

Description

A pool of pre-allocated MagicRing buffers for reuse.

Allocating a magic ring costs memfd_create + ftruncate + 3× mmap + memset per ring. This pool keeps a bounded free list of rings so connection churn doesn't repeat that syscall work.

Rings are stored as raw (Ptr Word8, Int) pairs — no IORefs, no per-ring mutable state. The transport-layer cursor state (head, tail, open/closed) is always fresh per connection; only the underlying mmap'd memory is recycled.

Synopsis

Documentation

data RingPool Source #

The pool is just a bounded free list protected by an MVar. All rings in the list have the same allocated size (the first allocation's rounded-up size sets the class).

closeRingPool :: RingPool -> IO () Source #

Destroy all idle rings. The pool remains usable (acquire allocates fresh, release destroys immediately).

acquireRing :: forall {k} (s :: k). RingPool -> Int -> IO (MagicRing s) Source #

Take a ring from the pool or allocate a fresh one.

releaseRing :: forall {k} (s :: k). RingPool -> MagicRing s -> IO () Source #

Return a ring to the pool. Destroyed immediately if the pool is full.