MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_anularis.h File Reference

Single-producer, single-consumer byte ring, a segment view over it, and loculus keepouts. More...

#include "mmgr.h"

Go to the source code of this file.

Data Structures

struct  mmgr_ring_span
 A byte region a pinned loculus retains out: the storage, its extent, and how far a reader got. More...
struct  mmgr_ring
 Storage a caller declares for one ring, whose contents belong to the implementation. More...
struct  AnularisCfg
 Arguments for every mmgr_anular_ entry, each reading only the members it needs. More...
struct  MemoriaAnularisNs
 Type of the anularis dispatch table. More...

Macros

#define MMGR_RING_WORDS
 Size of the ring storage a caller declares, counted in size_t units.
#define MMGR_RING_LOCULI_MAX
 Loculi a mask can address, which is one bit per loculus in a machine word.
#define MMGR_RING_LOCULI
 Loculi this build reserves, which a build may set before it includes this header.
#define MMGR_RING_POW2(count_)
 Asserts the loculi a build declares fit in one machine word.
#define MMGR_RING_WRAP(index_, capacity_)
 Wraps a ring offset back into a ring of capacity_ bytes.
#define MemoriaAnularis(name_, pool_)
 Declares a ring's storage and claims the pool under it.

Functions

EMBED_HOST_DEVICE embed_bool mmgr_anular_init (const AnularisCfg *args)
 Lays a fresh ring into args->ring, over the bytes at args->buf.
EMBED_HOST_DEVICE size_t mmgr_anular_available (const AnularisCfg *args)
 Returns the bytes ready for a read.
EMBED_HOST_DEVICE size_t mmgr_anular_vacant (const AnularisCfg *args)
 Returns the bytes still free to write.
EMBED_HOST_DEVICE embed_bool mmgr_anular_read_byte (const AnularisCfg *args)
 Takes one byte into args->dst and advances the tail past it.
EMBED_HOST_DEVICE size_t mmgr_anular_read (const AnularisCfg *args)
 Takes up to args->bytes into args->dst and advances the tail once at the end.
EMBED_HOST_DEVICE void mmgr_anular_peek (const AnularisCfg *args)
 Copies args->bytes from args->offset ahead of the tail into args->dst, and leaves the tail alone.
EMBED_HOST_DEVICE void mmgr_anular_consume (const AnularisCfg *args)
 Advances the tail past args->bytes.
EMBED_HOST_DEVICE embed_bool mmgr_anular_put (const AnularisCfg *args)
 Writes args->bytes of args->src into the ring, or refuses the whole span.
EMBED_HOST_DEVICE size_t mmgr_anular_seg_inflight (const AnularisCfg *args)
 Returns the segments filled and not yet released.
EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_next (const AnularisCfg *args)
 Reports the index of the segment the producer fills next.
EMBED_HOST_DEVICE void mmgr_anular_seg_publish (const AnularisCfg *args)
 Makes the filled segment visible to the consumer.
EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_front (const AnularisCfg *args)
 Reports the index of the segment the consumer takes next.
EMBED_HOST_DEVICE void mmgr_anular_seg_release (const AnularisCfg *args)
 Frees the front segment.
EMBED_HOST_DEVICE uint8_t * mmgr_anular_seg_at (const AnularisCfg *args)
 Returns the contiguous span of segment args->index.
EMBED_HOST_DEVICE embed_word mmgr_anular_loculus_ready (const AnularisCfg *args)
 Returns the loculi that are free and not pinned.
EMBED_HOST_DEVICE embed_iword mmgr_anular_loculus_next (const AnularisCfg *args)
 Returns the index of the lowest set bit of args->mask.
EMBED_HOST_DEVICE embed_bool mmgr_anular_loculus_hold (const AnularisCfg *args)
 Takes loculus args->index and records the args->bytes at args->src that it retains out.
EMBED_HOST_DEVICE const mmgr_ring_span * mmgr_anular_loculus_keepout (const AnularisCfg *args)
 Returns the region loculus args->index retains out.
EMBED_HOST_DEVICE void mmgr_anular_loculus_drop (const AnularisCfg *args)
 Gives loculus args->index back.
EMBED_HOST_DEVICE void mmgr_anular_loculus_mark (const AnularisCfg *args)
 Marks loculus args->index free.

Variables

static const MemoriaAnularisNs anularis
 Dispatch table instance named anularis, whose members are the mmgr_anular_ entries.

Detailed Description

Single-producer, single-consumer byte ring, a segment view over it, and loculus keepouts.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-08-29
Note
Nothing of the implementation appears here. mmgr_ring is a run of opaque bytes, and no header a consumer can reach declares the state positioned into it. That lets the layout change with no recompile of a consumer against a different struct.
The caller declares the ring and supplies the bytes; every index, mask and span is the ring's.
Exactly one producer advances head and exactly one consumer advances tail. So ordering is all it takes, and no entry takes a lock or a read-modify-write on those two.
No byte of the ring is ever scrubbed, and a drop leaves the loculus record alone. A restream can run again. Only mmgr_anular_init clears those records.

Definition in file memoria_anularis.h.