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

A prison site: a caller's storage divided into cellblocks, with the warden that holds them. More...

#include "mmgr.h"
#include "embed_atomic.h"
#include "embed_turnstile.h"

Go to the source code of this file.

Data Structures

struct  CellOwner
 Asserts MMGR_CARCER_ALIGN is a power of two. More...
struct  SeriesCellularum
 One cellblock's state: its bytes, the two boundaries that grow toward each other, the closed word a writer holds, the sink a refused store lands on, and the turnstiles every pass goes through. More...
struct  CarcerMovableInitCfg
 What a program gives a cellblock for the movable option, once, through its guard's movable_init. More...
struct  CarcerMovableCfg
 Arguments for the calls that reach a movable cell's bytes, each reading the members it names. More...
struct  MinimumSecurityGuard
 The minimum security guard over one cellblock: a released cell keeps whatever is in it. More...
struct  MaximumSecurityGuard
 The maximum security guard over one cellblock: every release zeroes the cell first. More...

Macros

#define MMGR_ENABLE_HW_MEM_CAPACITY_CB
 Set to 1 to track each tier's high-water mark.
#define MMGR_CARCER_OWNERS
 The most owners a program's owner table holds.
#define MMGR_MOVABLE_SETTLE_PERCENT
 The fragmentation at which a cellblock's mover sorts its movable cells, as a percentage of the bytes its persistent tier occupies.
#define MMGR_MOVABLE_READ_MS
 The milliseconds between the mover's readings of its cellblock.
#define MMGR_MOVABLE_QUIET_READINGS
 The readings in a row that must find the cellblock quiet before the mover sorts.
#define MMGR_MOVABLE_BACKOFF_MOST_MS
 The longest the mover waits between readings after a sort it backed off from.
#define MMGR_CARCER_ALIGN
 Alignment every prisoner is handed out at: one machine word, or the atomic size word's alignment where that is wider.
#define MMGR_OWNER_PLACE_BITS
 The owner word a cell carries behind its payload, one machine word laid as fields, high to low: the owner's place in the table, the completion bit, signaling bits, and the nanosecond the cell was taken on the library's clock, rolling over its bits.
#define MMGR_OWNER_SIGNAL_BITS
#define MMGR_OWNER_TIME_BITS
#define MMGR_OWNER_TIME_MASK
#define MMGR_OWNER_SIGNAL_SHIFT
#define MMGR_OWNER_COMPLETE
#define MMGR_OWNER_PLACE_SHIFT
#define MMGR_OWNER_PLACE_MASK
#define MMGR_OWNER_PLACE(name_, text_)
 One owner's place in the table, counted from 0, as the enumeration MMGR_OWNERS lays names it.
#define MMGR_OWNER_RECORD(name_, text_)
 One owner's record as the table's initializer lays it: its name, its place from 1, nothing counted.
#define MMGR_OWNER_POINTER(name_, text_)
 One owner's identity defined: a const pointer to its record in the table, resolved by the linker.
#define MMGR_OWNER_EXTERN(name_, text_)
 One owner's identity declared, for the header the owner's module reads it through.
#define MMGR_OWNERS(list_)
 The program's owners declared as data: the table laid, its count, and each owner's identity defined.
#define MMGR_CARCER_HALF_BITS
 The bits each boundary has in the word that carries both, half the atomic size word, and the mask of a half.
#define MMGR_CARCER_HALF_MASK
#define MMGR_CARCER_BYTES_MOST
 The most bytes one cellblock may hold: half a boundary's reach. The other half is the headroom the bumps a round refuses move the boundary into before the next writer settles it.
#define MMGR_CARCER_WANT_MOST
 The most payload one bump may ask: the headroom shared by the bumps in flight on the turnstiles' lanes, each of which may move its boundary once past MMGR_CARCER_BYTES_MOST before the refusal stops the rest. A take past it goes to the writer's path at once.
#define MMGR_CARCER_STATE_HW
 The high-water members' first values, or nothing where the build tracks none.
#define MMGR_CARCER_STATE(base_, bytes_)
 A cellblock's state as it stands over bytes_ bytes at base_ with no cell taken: both tiers empty, every mark at zero, and the turnstiles left to the zeroing of the storage they stand in.
#define MMGR_MOVABLE_HEAD_BYTES
 Bytes of the option's state ahead of its turnstiles, which locus_carcerum.c asserts it fits.
#define MMGR_MOVABLE_CLAIM_BITS
 The bits of one word of the option's claim bits: one an entry.
#define MMGR_MOVABLE_STORAGE_BYTES(cells_, width_, rows_)
 The storage the movable option takes for a table of cells_ entries and rows_ rows of touches.
#define MMGR_CARCER_MOVABLE_ENTRIES(prisonsite_, name_, wipe_to_zero_on_release_, series_cellularum_)
 The movable entries of one cellblock, bound to it through series_cellularum_.
#define MMGR_CARCER_BODY(prisonsite_, type_, name_, wipe_to_zero_on_release_)
 Everything one cellblock is: its bytes, its state, and the entries bound to it.
#define MMGR_CARCER_MEM(prisonsite_, type_, name_, wipe_to_zero_on_release_)
 One cellblock as a member of its site's type.
#define MMGR_CARCER_SEAT(prisonsite_, type_, name_, wipe_to_zero_on_release_)
 One cellblock's entries, in the order its guard declares them.
#define MMGR_MINIMUM_SECURITY(name_)
 Declares a minimum security cellblock over a pool.
#define MMGR_MAXIMUM_SECURITY(name_)
 Declares a maximum security cellblock over a pool.
#define MMGR_UNTUPLE(...)
 Strips a tuple's parentheses.
#define MMGR_CARCER_APPLY(what_, prisonsite_, tuple_)
 Applies one reader to one cellblock tuple, with the site spliced in ahead of it.
#define MMGR_CARCER_APPLY_(what_, prisonsite_, ...)
 Expands to what_(prisonsite_, VA_ARGS).
#define MMGR_CARCER_W1(what_, prisonsite_, SeriesCellularum1_)
 Applies the reader to a site's one cellblock tuple.
#define MMGR_CARCER_W2(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_)
 Applies the reader to a site's two cellblock tuples.
#define MMGR_CARCER_W3(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_)
 Applies the reader to a site's three cellblock tuples.
#define MMGR_CARCER_W4(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_)
 Applies the reader to a site's four cellblock tuples.
#define MMGR_CARCER_W5(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, SeriesCellularum5_)
 Applies the reader to a site's five cellblock tuples.
#define MMGR_CARCER_W6(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_)
 Applies the reader to a site's six cellblock tuples.
#define MMGR_CARCER_W7(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_, SeriesCellularum7_)
 Applies the reader to a site's seven cellblock tuples.
#define MMGR_CARCER_W8(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_, SeriesCellularum7_, SeriesCellularum8_)
 Applies the reader to a site's eight cellblock tuples.
#define MMGR_CARCER_WALK(what_, prisonsite_, ...)
 Expands the walk matching the cellblock count.
#define LocusCarcerum(prisonsite_, ...)
 Declares a prison site and the cellblocks built at it.

Typedefs

typedef struct CarcerMovableEntry CarcerMovableEntry
 The identity a movable cell's taker holds: a const pointer to the cell's entry in the cellblock's translation table.

Functions

uint64_t mmgr_carcer_hw_clock_ns (void)
 The library's clock in nanoseconds, which a cell's owner word carries the take on.
embed_bool mmgr_owner_listed (const CellOwner *owner)
 Whether an owner is one of the table's.
static size_t mmgr_owner_in_use (const CellOwner *owner)
 The payload bytes of the cells an owner has now.
static size_t mmgr_owner_hw (const CellOwner *owner)
 The most payload bytes an owner has had at once.
void mmgr_carcer_hw_misnamed (const CellOwner *named, const CellOwner *cell_owner, size_t bytes)
 Told of each give or growth that names an owner other than the one the cell counts to.
static size_t mmgr_series_cellularum_persistent_end (const SeriesCellularum *series)
 Offset just past the last persistent cell.
static size_t mmgr_series_cellularum_temporary_top (const SeriesCellularum *series)
 Offset of the lowest temporary cell.
static embed_bool mmgr_series_cellularum_idle (const SeriesCellularum *series)
 Whether no cell is taken from a cellblock.
static size_t mmgr_series_cellularum_persistent_hw (const SeriesCellularum *series)
 The furthest a cellblock's persistent tier has reached.
static size_t mmgr_series_cellularum_temporary_hw (const SeriesCellularum *series)
 The most bytes a cellblock's temporary tier has taken from the top.
void * mmgr_persistent_buf_alloc (SeriesCellularum *series, size_t size, const CellOwner *owner)
 Takes size bytes from a cellblock's persistent tier.
void * mmgr_persistent_max_security_buf_alloc (SeriesCellularum *series, size_t size, const CellOwner *owner)
 Takes size bytes from a maximum security cellblock's persistent tier.
void mmgr_persistent_buf_release (SeriesCellularum *series, void *prisoner, const CellOwner *owner)
 Releases a prisoner, leaving the cell's bytes as they are.
void mmgr_persistent_max_security_buf_release (SeriesCellularum *series, void *prisoner, const CellOwner *owner)
 Zeroes a cell, then releases the prisoner.
void * mmgr_buf_grow (SeriesCellularum *series, void *prisoner, size_t size, const CellOwner *owner)
 Grows a cell to size payload bytes in place, where it is the newest cell of its tier.
void * mmgr_max_security_buf_grow (SeriesCellularum *series, void *prisoner, size_t size, const CellOwner *owner)
 Grows a cell in place as mmgr_buf_grow does, and zeroes the bytes the growth adds.
void * mmgr_temporary_buf_alloc (SeriesCellularum *series, size_t size, const CellOwner *owner)
 Takes size bytes from a cellblock's temporary tier.
void * mmgr_temporary_max_security_buf_alloc (SeriesCellularum *series, size_t size, const CellOwner *owner)
 Takes size bytes from a maximum security cellblock's temporary tier.
embed_bool mmgr_who_owns_buf (const SeriesCellularum *series, const void *at)
 Whether at lies inside the cellblock's bytes.
const CellOwner * mmgr_owner_of_buf (const SeriesCellularum *series, const void *prisoner)
 The owner a cell counts to, read off the word behind its payload.
size_t mmgr_buf_available (SeriesCellularum *series)
 The bytes lying between the two tiers.
void mmgr_zero_buf (void *prisoner, size_t size)
 Zeroes size bytes at prisoner, releasing nothing.
size_t mmgr_align_up_buf (size_t size)
 Rounds size up to a whole machine word.
void mmgr_series_cellularum_emptied (SeriesCellularum *series)
 Puts a cellblock back to the state it was declared in: both tiers empty, the closed word and the turnstiles at rest, the option unassigned, and no byte of its storage touched.
void mmgr_owner_bytes_taken (const CellOwner *owner, size_t bytes)
 Counts bytes that lie in no cellblock to an owner, as a ring's or a page's are.
void mmgr_owner_bytes_given (const CellOwner *owner, size_t bytes)
 Takes bytes mmgr_owner_bytes_taken counted off their owner.
size_t mmgr_series_cellularum_fragmentation (const SeriesCellularum *series)
 A cellblock's fragmentation: the bytes its persistent tier occupies and no cell's payload holds, as a percentage of the bytes it occupies.
embed_bool mmgr_movable_init (SeriesCellularum *series, const CarcerMovableInitCfg *args, embed_bool wipes)
 Assigns a cellblock's movable option: the translation table, its claim bits, the rows of touches and the mover's thread. A cellblock's guard calls this, as movable_init.
const CarcerMovableEntry * mmgr_movable_buf_alloc (SeriesCellularum *series, size_t size, const CellOwner *owner)
 Takes a persistent cell a move may move, and names it in the table.
embed_bool mmgr_movable_buf_release (SeriesCellularum *series, const CarcerMovableEntry *cell, const CellOwner *owner)
 Gives a movable cell back and frees its entry.
embed_bool mmgr_movable_buf_read (const SeriesCellularum *series, const CarcerMovableCfg *args)
 Copies args->bytes from args->offset of a movable cell to args->dst.
embed_bool mmgr_movable_buf_write (SeriesCellularum *series, const CarcerMovableCfg *args)
 Copies args->bytes from args->src to args->offset of a movable cell.
embed_iword mmgr_movable_buf_compare (const SeriesCellularum *series, const CarcerMovableCfg *args)
 Orders args->bytes of a movable cell against args->src, or against another cell where args->other_cell is set.
size_t mmgr_movable_buf_measure (const SeriesCellularum *series, const CarcerMovableCfg *args)
 The bytes from args->offset of a movable cell to the next zero byte.
embed_bool mmgr_movable_buf_move (SeriesCellularum *series)
 Moves one movable cell into the first free cell below it, highest cell first.
void mmgr_movable_run (SeriesCellularum *series)
 The mover: what the thread the program gave runs, until its thread_wait answers EMBED_FALSE.
size_t mmgr_movable_queue_depth (const SeriesCellularum *series)
 The contexts queued at the cellblock's turnstiles now: those that found every open lane busy and wait for a lane.
embed_bool mmgr_movable_touches (const SeriesCellularum *series, size_t at, size_t *id, size_t *touches)
 One row of touches a lane, counted as passes go through it.

Variables

CellOwner mmgr_owner_table []
 The program's owner table and the owners in it, which MMGR_OWNERS defines once.
const size_t mmgr_owner_table_count

Detailed Description

A prison site: a caller's storage divided into cellblocks, with the warden that holds them.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-08-29
Note
LocusCarcerum() emits each cellblock's state and the warden that holds them and that every call goes through, all as initialized data. Nothing runs at startup. A configuration the asserts reject fails the build.
The storage is the caller's. A cellblock is declared over a pool - ParsMemoriaeInternae or ParsMemoriaeExternum in mmgr.h - and its SeriesCellularum record holds that pool's address. The linker resolves it. No call computes a cellblock's address from a site and an index, and which memory a cellblock sits in was settled where its pool was declared.
A cellblock has two tiers. The persistent tier runs up from base and the temporary tier runs down from size. Both boundaries are the two halves of one atomic word, and a take moves its own half by one fetch-add whose old value carries the other, through the cellblock's turnstiles.
A cellblock's declaration picks its security level. MMGR_MINIMUM_SECURITY leaves a cell's bytes as they are on release. MMGR_MAXIMUM_SECURITY zeroes them. The warden is const: nothing after the declaration can change the level a cellblock runs at.
The public entries are English and the internals are Latin, this filename included.
spatium provides the spans over those bytes.

Definition in file locus_carcerum.h.

Macro Definition Documentation

◆ MMGR_ENABLE_HW_MEM_CAPACITY_CB

#define MMGR_ENABLE_HW_MEM_CAPACITY_CB

Set to 1 to track each tier's high-water mark.

Note
Off by default because the two marks cost a size_t each in every SeriesCellularum, and a build that never reads them should not carry them.
Adds SeriesCellularum::persistent_hw and SeriesCellularum::temporary_hw, and the update that raises them in carcer_grow, which both tiers reach. One mark per tier: neither counts the other's bytes.
The #ifndef leaves a build's own definition standing, whether it arrives on the command line or from a header included ahead of this one.
Takes 0 or 1 alone. Both readers are #if, which would take any non-zero as set. The check below keeps a mistyped value from quietly widening every SeriesCellularum.

Definition at line 50 of file locus_carcerum.h.

◆ MMGR_CARCER_OWNERS

#define MMGR_CARCER_OWNERS

The most owners a program's owner table holds.

Note
The table is the program's one list of owners, laid by MMGR_OWNERS in the order they are declared, and an owner's place in it is its key. A declaration past this count fails the build.

Definition at line 63 of file locus_carcerum.h.

◆ MMGR_MOVABLE_SETTLE_PERCENT

#define MMGR_MOVABLE_SETTLE_PERCENT

The fragmentation at which a cellblock's mover sorts its movable cells, as a percentage of the bytes its persistent tier occupies.

Note
mmgr_series_cellularum_fragmentation reads what the build compares against this.

Definition at line 73 of file locus_carcerum.h.

◆ MMGR_MOVABLE_READ_MS

#define MMGR_MOVABLE_READ_MS

The milliseconds between the mover's readings of its cellblock.

Definition at line 81 of file locus_carcerum.h.

◆ MMGR_MOVABLE_QUIET_READINGS

#define MMGR_MOVABLE_QUIET_READINGS

The readings in a row that must find the cellblock quiet before the mover sorts.

Definition at line 86 of file locus_carcerum.h.

◆ MMGR_MOVABLE_BACKOFF_MOST_MS

#define MMGR_MOVABLE_BACKOFF_MOST_MS

The longest the mover waits between readings after a sort it backed off from.

Definition at line 91 of file locus_carcerum.h.

◆ MMGR_CARCER_ALIGN

#define MMGR_CARCER_ALIGN

Alignment every prisoner is handed out at: one machine word, or the atomic size word's alignment where that is wider.

Note
Derived from the two types in place of a number. Every cell carries an atomic size word at its header and at its foot, and a cell's offset and payload are whole multiples of this, and each of those words lands at its own alignment at every width.
LocusCarcerum() puts this alignment on the storage it declares. This rounds only running offsets inside a cellblock.

Definition at line 107 of file locus_carcerum.h.

◆ MMGR_OWNER_PLACE_BITS

#define MMGR_OWNER_PLACE_BITS

The owner word a cell carries behind its payload, one machine word laid as fields, high to low: the owner's place in the table, the completion bit, signaling bits, and the nanosecond the cell was taken on the library's clock, rolling over its bits.

Note
The owner test is one AND: the word's place field against an owner's place. A word whose place field is 0 names no owner, as a free cell's does. The completion bit is set once, by the one context whose swap lands, when the cell's bytes come off its owner: two gives reaching the same cell count it off once between them. The signaling bits are the cellblock's to raise and read with one atomic step each. The timestamp is what the cell's take read on mmgr_carcer_hw_clock_ns, in the bits left, and a reader of lifetimes takes it as rolling.
The place field is sized from MMGR_CARCER_OWNERS, the fewest bits every owner's place fits, from 4 to 16; then 1 completion bit, 3 signaling bits, and the timestamp in the bits left, the word's width less those: 1024 owners on a 64-bit word leave 49 timestamp bits, on a 32-bit word 17, rolling every 131 microseconds, and on a 16-bit word 1. The layout fails the build where no timestamp bit is left.

Definition at line 175 of file locus_carcerum.h.

◆ MMGR_OWNER_SIGNAL_BITS

#define MMGR_OWNER_SIGNAL_BITS

Definition at line 203 of file locus_carcerum.h.

◆ MMGR_OWNER_TIME_BITS

#define MMGR_OWNER_TIME_BITS

Definition at line 206 of file locus_carcerum.h.

◆ MMGR_OWNER_TIME_MASK

#define MMGR_OWNER_TIME_MASK

Definition at line 207 of file locus_carcerum.h.

◆ MMGR_OWNER_SIGNAL_SHIFT

#define MMGR_OWNER_SIGNAL_SHIFT

Definition at line 208 of file locus_carcerum.h.

◆ MMGR_OWNER_COMPLETE

#define MMGR_OWNER_COMPLETE

Definition at line 209 of file locus_carcerum.h.

◆ MMGR_OWNER_PLACE_SHIFT

#define MMGR_OWNER_PLACE_SHIFT

Definition at line 210 of file locus_carcerum.h.

◆ MMGR_OWNER_PLACE_MASK

#define MMGR_OWNER_PLACE_MASK

Definition at line 211 of file locus_carcerum.h.

◆ MMGR_OWNER_PLACE

#define MMGR_OWNER_PLACE ( name_,
text_ )

One owner's place in the table, counted from 0, as the enumeration MMGR_OWNERS lays names it.

Parameters
[in]name_The owner's identity, as declared.
[in]text_The owner's name as a reader prints it, unread here.

Definition at line 239 of file locus_carcerum.h.

◆ MMGR_OWNER_RECORD

#define MMGR_OWNER_RECORD ( name_,
text_ )

One owner's record as the table's initializer lays it: its name, its place from 1, nothing counted.

Parameters
[in]name_The owner's identity, as declared.
[in]text_The owner's name as a reader prints it [BORROWS].

Definition at line 247 of file locus_carcerum.h.

◆ MMGR_OWNER_POINTER

#define MMGR_OWNER_POINTER ( name_,
text_ )

One owner's identity defined: a const pointer to its record in the table, resolved by the linker.

Parameters
[in]name_The owner's identity, as declared.
[in]text_The owner's name as a reader prints it, unread here.

Definition at line 256 of file locus_carcerum.h.

◆ MMGR_OWNER_EXTERN

#define MMGR_OWNER_EXTERN ( name_,
text_ )

One owner's identity declared, for the header the owner's module reads it through.

Parameters
[in]name_The owner's identity, as declared.
[in]text_The owner's name as a reader prints it, unread here.

Definition at line 264 of file locus_carcerum.h.

◆ MMGR_OWNERS

#define MMGR_OWNERS ( list_)

The program's owners declared as data: the table laid, its count, and each owner's identity defined.

Parameters
[in]list_The program's list of owners, a macro taking one macro and applying it to each owner as list_(macro_) expanding to macro_(name_, text_) for every owner, name_ the identity the owner's module names and text_ the name a reader prints.
Note
Expanded once, in the translation unit that owns the program's memory. The enumeration gives each owner its place, the table is sized to the owners declared and holds their records in that order, and each identity is a pointer into it the linker resolves: there is no registration and nothing runs before the first take. A list longer than MMGR_CARCER_OWNERS fails the build.

Definition at line 277 of file locus_carcerum.h.

◆ MMGR_CARCER_HALF_BITS

#define MMGR_CARCER_HALF_BITS

The bits each boundary has in the word that carries both, half the atomic size word, and the mask of a half.

Definition at line 337 of file locus_carcerum.h.

Referenced by mmgr_series_cellularum_temporary_top().

◆ MMGR_CARCER_HALF_MASK

#define MMGR_CARCER_HALF_MASK

Definition at line 338 of file locus_carcerum.h.

◆ MMGR_CARCER_BYTES_MOST

#define MMGR_CARCER_BYTES_MOST

The most bytes one cellblock may hold: half a boundary's reach. The other half is the headroom the bumps a round refuses move the boundary into before the next writer settles it.

Note
LocusCarcerum() asserts each pool against this. A cell's header carries a size this large in the bits above its two state bits.

Definition at line 347 of file locus_carcerum.h.

◆ MMGR_CARCER_WANT_MOST

#define MMGR_CARCER_WANT_MOST

The most payload one bump may ask: the headroom shared by the bumps in flight on the turnstiles' lanes, each of which may move its boundary once past MMGR_CARCER_BYTES_MOST before the refusal stops the rest. A take past it goes to the writer's path at once.

Definition at line 354 of file locus_carcerum.h.

◆ MMGR_CARCER_STATE_HW

#define MMGR_CARCER_STATE_HW

The high-water members' first values, or nothing where the build tracks none.

Definition at line 405 of file locus_carcerum.h.

◆ MMGR_CARCER_STATE

#define MMGR_CARCER_STATE ( base_,
bytes_ )

A cellblock's state as it stands over bytes_ bytes at base_ with no cell taken: both tiers empty, every mark at zero, and the turnstiles left to the zeroing of the storage they stand in.

Parameters
[in]base_First byte of the cellblock [BORROWS].
[in]bytes_Bytes in the cellblock.

Definition at line 415 of file locus_carcerum.h.

◆ MMGR_MOVABLE_HEAD_BYTES

#define MMGR_MOVABLE_HEAD_BYTES

Bytes of the option's state ahead of its turnstiles, which locus_carcerum.c asserts it fits.

Definition at line 487 of file locus_carcerum.h.

◆ MMGR_MOVABLE_CLAIM_BITS

#define MMGR_MOVABLE_CLAIM_BITS

The bits of one word of the option's claim bits: one an entry.

Definition at line 490 of file locus_carcerum.h.

◆ MMGR_MOVABLE_STORAGE_BYTES

#define MMGR_MOVABLE_STORAGE_BYTES ( cells_,
width_,
rows_ )

The storage the movable option takes for a table of cells_ entries and rows_ rows of touches.

Parameters
[in]cells_Movable cells the table can name at once.
[in]width_The lanes open bound the mover reads quiet under, which takes no storage.
[in]rows_Rows of touches.
Note
A constant expression, so that a pool can be declared at this size: the state, one word an entry, one claim bit an entry in whole words, and two words a row.

Definition at line 501 of file locus_carcerum.h.

◆ MMGR_CARCER_MOVABLE_ENTRIES

#define MMGR_CARCER_MOVABLE_ENTRIES ( prisonsite_,
name_,
wipe_to_zero_on_release_,
series_cellularum_ )

The movable entries of one cellblock, bound to it through series_cellularum_.

Parameters
[in]prisonsite_Site whose name every entry symbol carries.
[in]name_Pool whose name the symbols carry alongside the site's.
[in]wipe_to_zero_on_release_Security flag, which the option keeps for its releases and moves.
[in]series_cellularum_The cellblock's record, as a pointer expression.

Definition at line 667 of file locus_carcerum.h.

◆ MMGR_CARCER_BODY

#define MMGR_CARCER_BODY ( prisonsite_,
type_,
name_,
wipe_to_zero_on_release_ )

Everything one cellblock is: its bytes, its state, and the entries bound to it.

Parameters
[in]prisonsite_Site the cellblock is built at, which every emitted symbol carries.
[in]type_MinimumSecurityGuard or MaximumSecurityGuard, read by MMGR_CARCER_MEM.
[in]name_Pool the cellblock is built over, which is also the name it is reached by as a member of its site [BORROWS].
[in]wipe_to_zero_on_release_1 where a release zeroes the cell first, 0 where it does not.
Note
The site name is part of every symbol. Two sites may each hold a cellblock of the same name, at different security levels, without colliding.
wipe_to_zero_on_release_ is a literal: the branch it guards folds away and the security level costs nothing to read.
The extent comes from the pool two ways. name_##_bytes is the count its declaration was handed and is what the record carries, and sizeof is what the compiler laid down. The asserts test the second: they say something the first cannot say about itself.
Warning
A pool too small to hold one cell fails the build. Only the alignment is a power of two, and nothing reads the size as a mask. A bad size is a mistake the language would otherwise accept. A wrong name or guard type fails on its own, and two pools are separate objects: they cannot share an address and there is no overlap to check.
Note
No upper bound. The pool states how much storage the cellblock gets, and nothing in the library sizes anything from a ceiling over it.

Definition at line 720 of file locus_carcerum.h.

◆ MMGR_CARCER_MEM

#define MMGR_CARCER_MEM ( prisonsite_,
type_,
name_,
wipe_to_zero_on_release_ )

One cellblock as a member of its site's type.

Parameters
[in]prisonsite_Site the cellblock is built at, unused here.
[in]type_MinimumSecurityGuard or MaximumSecurityGuard, the member's type.
[in]name_Pool the cellblock is built over, and the name the member is given.
[in]wipe_to_zero_on_release_Security flag, unused here.
Note
Takes all four because the three readers share one tuple shape, as MMGR_MINIMUM_SECURITY describes.

Definition at line 785 of file locus_carcerum.h.

◆ MMGR_CARCER_SEAT

#define MMGR_CARCER_SEAT ( prisonsite_,
type_,
name_,
wipe_to_zero_on_release_ )

One cellblock's entries, in the order its guard declares them.

Parameters
[in]prisonsite_Site whose name every entry symbol carries.
[in]type_Guard type, unused here.
[in]name_Pool whose name the symbols carry alongside the site's.
[in]wipe_to_zero_on_release_Security flag, unused here.
Note
MinimumSecurityGuard and MaximumSecurityGuard declare the same thirteen members in the same order. One initializer serves either level.

Definition at line 797 of file locus_carcerum.h.

◆ MMGR_MINIMUM_SECURITY

#define MMGR_MINIMUM_SECURITY ( name_)

Declares a minimum security cellblock over a pool.

Parameters
[in]name_Pool the cellblock is built over, which is also the name it is reached by as a member of its site [BORROWS].
Note
The pool carries its own extent: no size is written here. A cellblock is a dressing over bytes that already exist, and where those bytes live was settled by which of ParsMemoriaeInternae or ParsMemoriaeExternum declared them.
Expands to a tuple in place of code. The site reads the same list three times, once for the cellblocks' bodies, once for its own members, once for their entries. An element has to stay data until the site says which of the three it is being read as.

Definition at line 824 of file locus_carcerum.h.

◆ MMGR_MAXIMUM_SECURITY

#define MMGR_MAXIMUM_SECURITY ( name_)

Declares a maximum security cellblock over a pool.

Parameters
[in]name_Pool the cellblock is built over, which is also the name it is reached by as a member of its site [BORROWS].
Note
The trailing 1 is the wipe flag MMGR_CARCER_BODY reads to pick the zeroing release on both tiers. Choosing this over MMGR_MINIMUM_SECURITY is where a cellblock's level is settled, and nothing after the declaration can change it.
Carries no size, for the reason MMGR_MINIMUM_SECURITY gives.

Definition at line 836 of file locus_carcerum.h.

◆ MMGR_UNTUPLE

#define MMGR_UNTUPLE ( ...)

Strips a tuple's parentheses.

Parameters
[in]...The tuple's elements, which its own parentheses deliver as this macro's arguments.
Returns
Those elements, comma separated, with nothing around them.
Note
Written MMGR_UNTUPLE tuple_, with no parentheses of its own: the tuple supplies them.

Definition at line 845 of file locus_carcerum.h.

◆ MMGR_CARCER_APPLY

#define MMGR_CARCER_APPLY ( what_,
prisonsite_,
tuple_ )

Applies one reader to one cellblock tuple, with the site spliced in ahead of it.

Parameters
[in]what_Reader to apply: MMGR_CARCER_BODY, MMGR_CARCER_MEM or MMGR_CARCER_SEAT.
[in]prisonsite_Site, which reaches the reader ahead of the tuple's own elements.
[in]tuple_One MMGR_MINIMUM_SECURITY or MMGR_MAXIMUM_SECURITY tuple.
Returns
What the reader expands to.
Note
Two steps, because a macro's arguments are counted before they are expanded. The inner call lets the flattened tuple reach the reader as separate arguments.

Definition at line 857 of file locus_carcerum.h.

◆ MMGR_CARCER_APPLY_

#define MMGR_CARCER_APPLY_ ( what_,
prisonsite_,
... )

Expands to what_(prisonsite_, VA_ARGS).

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader ahead of the elements.
[in]...The tuple's elements, already flattened by MMGR_UNTUPLE.
Returns
What the reader expands to.
Note
The inner half of MMGR_CARCER_APPLY's two steps. Its arguments are expanded before they are substituted: MMGR_UNTUPLE runs here and the tuple's elements reach the reader as separate arguments in place of one.

Definition at line 870 of file locus_carcerum.h.

◆ MMGR_CARCER_W1

#define MMGR_CARCER_W1 ( what_,
prisonsite_,
SeriesCellularum1_ )

Applies the reader to a site's one cellblock tuple.

Parameters
[in]what_Reader to apply: MMGR_CARCER_BODY, MMGR_CARCER_MEM or MMGR_CARCER_SEAT.
[in]prisonsite_Site, which reaches the reader ahead of the tuple's own elements.
[in]SeriesCellularum1_The cellblock's tuple.
Note
The base of the expansion. Every longer line ends in this one, and it alone names no other.

Definition at line 880 of file locus_carcerum.h.

◆ MMGR_CARCER_W2

#define MMGR_CARCER_W2 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_ )

Applies the reader to a site's two cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple, which MMGR_CARCER_W1 takes.
[in]SeriesCellularum2_Second cellblock's tuple, applied after it.
Note
The step every longer line repeats: expand the line one shorter, then apply the reader once more. The preprocessor cannot step through a list: each cellblock count needs a line of its own.

Definition at line 893 of file locus_carcerum.h.

◆ MMGR_CARCER_W3

#define MMGR_CARCER_W3 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_ )

Applies the reader to a site's three cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple, applied after MMGR_CARCER_W2 expands the first two.
Note
MMGR_CARCER_WALK selects this line for a site declaring three cellblocks.

Definition at line 907 of file locus_carcerum.h.

◆ MMGR_CARCER_W4

#define MMGR_CARCER_W4 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_,
SeriesCellularum4_ )

Applies the reader to a site's four cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple.
[in]SeriesCellularum4_Fourth cellblock's tuple, applied after MMGR_CARCER_W3 expands the first three.
Note
MMGR_CARCER_WALK selects this line for a site declaring four cellblocks.

Definition at line 922 of file locus_carcerum.h.

◆ MMGR_CARCER_W5

#define MMGR_CARCER_W5 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_,
SeriesCellularum4_,
SeriesCellularum5_ )

Applies the reader to a site's five cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple.
[in]SeriesCellularum4_Fourth cellblock's tuple.
[in]SeriesCellularum5_Fifth cellblock's tuple, applied after MMGR_CARCER_W4 expands the first four.
Note
MMGR_CARCER_WALK selects this line for a site declaring five cellblocks.

Definition at line 939 of file locus_carcerum.h.

◆ MMGR_CARCER_W6

#define MMGR_CARCER_W6 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_,
SeriesCellularum4_,
SeriesCellularum5_,
SeriesCellularum6_ )

Applies the reader to a site's six cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple.
[in]SeriesCellularum4_Fourth cellblock's tuple.
[in]SeriesCellularum5_Fifth cellblock's tuple.
[in]SeriesCellularum6_Sixth cellblock's tuple, applied after MMGR_CARCER_W5 expands the first five.
Note
MMGR_CARCER_WALK selects this line for a site declaring six cellblocks.

Definition at line 957 of file locus_carcerum.h.

◆ MMGR_CARCER_W7

#define MMGR_CARCER_W7 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_,
SeriesCellularum4_,
SeriesCellularum5_,
SeriesCellularum6_,
SeriesCellularum7_ )

Applies the reader to a site's seven cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple.
[in]SeriesCellularum4_Fourth cellblock's tuple.
[in]SeriesCellularum5_Fifth cellblock's tuple.
[in]SeriesCellularum6_Sixth cellblock's tuple.
[in]SeriesCellularum7_Seventh cellblock's tuple, applied after MMGR_CARCER_W6 expands the first six.
Note
MMGR_CARCER_WALK selects this line for a site declaring seven cellblocks.

Definition at line 977 of file locus_carcerum.h.

◆ MMGR_CARCER_W8

#define MMGR_CARCER_W8 ( what_,
prisonsite_,
SeriesCellularum1_,
SeriesCellularum2_,
SeriesCellularum3_,
SeriesCellularum4_,
SeriesCellularum5_,
SeriesCellularum6_,
SeriesCellularum7_,
SeriesCellularum8_ )

Applies the reader to a site's eight cellblock tuples.

Parameters
[in]what_Reader to apply.
[in]prisonsite_Site, which reaches the reader with every tuple.
[in]SeriesCellularum1_First cellblock's tuple.
[in]SeriesCellularum2_Second cellblock's tuple.
[in]SeriesCellularum3_Third cellblock's tuple.
[in]SeriesCellularum4_Fourth cellblock's tuple.
[in]SeriesCellularum5_Fifth cellblock's tuple.
[in]SeriesCellularum6_Sixth cellblock's tuple.
[in]SeriesCellularum7_Seventh cellblock's tuple.
[in]SeriesCellularum8_Eighth cellblock's tuple, applied after MMGR_CARCER_W7 expands the first seven.
Note
MMGR_CARCER_WALK selects this line for a site declaring eight cellblocks.
Warning
The last line written. A site declaring nine cellblocks pastes MMGR_CARCER_W9, which does not exist. Writing that line is the whole fix. Nothing else changes and no configured ceiling is involved.

Definition at line 1001 of file locus_carcerum.h.

◆ MMGR_CARCER_WALK

#define MMGR_CARCER_WALK ( what_,
prisonsite_,
... )

Expands the walk matching the cellblock count.

Parameters
[in]what_Reader to apply: MMGR_CARCER_BODY, MMGR_CARCER_MEM or MMGR_CARCER_SEAT.
[in]prisonsite_Site, forwarded to the walk ahead of the tuples.
[in]...MMGR_MINIMUM_SECURITY and MMGR_MAXIMUM_SECURITY tuples, one per cellblock.
Note
EMBED_CAT builds the line's name from EMBED_NARG's count of the tuples.
Warning
EMBED_NARG gives 1 for an empty list. A site declaring no cellblocks reaches MMGR_CARCER_W1 and fails there with too few arguments for the reader.

Definition at line 1018 of file locus_carcerum.h.

◆ LocusCarcerum

#define LocusCarcerum ( prisonsite_,
... )

Declares a prison site and the cellblocks built at it.

Parameters
[in]prisonsite_Name of the site. Its cellblocks are reached as members of it.
[in]...MMGR_MINIMUM_SECURITY and MMGR_MAXIMUM_SECURITY declarations, one each.
Note
Everything it emits is initialized data. Nothing runs at startup, and a cellblock's first byte is the address of its own storage, which the linker resolves.
The warden is the const struct this emits under the site's name. Every call reaches a cellblock through it.
Every emitted symbol carries the site's name. A program may declare as many sites as it likes and two of them may each hold a cellblock called the same thing.
A cellblock's entries are bound to that cellblock. No call names one and none can reach another's bytes. A minimum security cellblock has no zeroing release and a maximum security one has no plain release.
Warning
The bytes, the state and the warden are all static. A declaration in a header gives every translation unit that includes it a site of its own in place of one they share.

Definition at line 1038 of file locus_carcerum.h.

Typedef Documentation

◆ CarcerMovableEntry

The identity a movable cell's taker holds: a const pointer to the cell's entry in the cellblock's translation table.

Note
The entry is the mutable word, and it is MMgr's alone: it names where the cell stands now, and a move changes it. The pointer the caller holds never changes while the cell lives, however often the cell moves, and the layout is declared nowhere a caller can reach.

Definition at line 436 of file locus_carcerum.h.

Function Documentation

◆ mmgr_carcer_hw_clock_ns()

uint64_t mmgr_carcer_hw_clock_ns ( void )

The library's clock in nanoseconds, which a cell's owner word carries the take on.

Returns
The nanoseconds since a start the port chooses, wrapping at 2^64.
Note
Weak, and the default answers 0 every time: a build that defines none stamps every take 0. A port defines this name to replace it.

References mmgr_carcer_hw_clock_ns(), and mmgr_owner_table.

Referenced by mmgr_carcer_hw_clock_ns().

◆ mmgr_owner_listed()

embed_bool mmgr_owner_listed ( const CellOwner * owner)

Whether an owner is one of the table's.

Parameters
[in]ownerThe owner, which may be NULL [BORROWS].
Returns
EMBED_TRUE where it is the record standing at its own place in the table.

References mmgr_owner_listed().

Referenced by mmgr_owner_listed().

◆ mmgr_owner_in_use()

size_t mmgr_owner_in_use ( const CellOwner * owner)
inlinestatic

The payload bytes of the cells an owner has now.

Parameters
[in]ownerThe owner [BORROWS].
Returns
The bytes, off one word.

Definition at line 302 of file locus_carcerum.h.

References CellOwner::in_use, and mmgr_owner_in_use().

Referenced by mmgr_owner_in_use().

◆ mmgr_owner_hw()

size_t mmgr_owner_hw ( const CellOwner * owner)
inlinestatic

The most payload bytes an owner has had at once.

Parameters
[in]ownerThe owner [BORROWS].
Returns
The bytes, off one word.

Definition at line 314 of file locus_carcerum.h.

References CellOwner::hw, and mmgr_owner_hw().

Referenced by mmgr_owner_hw().

◆ mmgr_carcer_hw_misnamed()

void mmgr_carcer_hw_misnamed ( const CellOwner * named,
const CellOwner * cell_owner,
size_t bytes )

Told of each give or growth that names an owner other than the one the cell counts to.

Parameters
[in]namedThe owner the give or the growth named [BORROWS].
[in]cell_ownerThe owner the cell counts to, NULL where its owner word names no registered owner [BORROWS].
[in]bytesThe cell's payload bytes.
Note
Such a give or growth is refused and changes nothing: the cell stays with its holder, counted to its owner. A program that sees this has a give in the wrong place, and a port logs it.
Weak, and the default does nothing. A port defines this name to replace it.

References mmgr_carcer_hw_misnamed().

Referenced by mmgr_carcer_hw_misnamed().

◆ mmgr_series_cellularum_persistent_end()

size_t mmgr_series_cellularum_persistent_end ( const SeriesCellularum * series)
inlinestatic

Offset just past the last persistent cell.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The persistent end, in bytes.
Note
The end as the word holds it. A trim a give left owed on the open word does not run here; mmgr_buf_available and the next take run it.

Definition at line 514 of file locus_carcerum.h.

References SeriesCellularum::bounds, and mmgr_series_cellularum_persistent_end().

Referenced by mmgr_series_cellularum_idle(), and mmgr_series_cellularum_persistent_end().

◆ mmgr_series_cellularum_temporary_top()

size_t mmgr_series_cellularum_temporary_top ( const SeriesCellularum * series)
inlinestatic

Offset of the lowest temporary cell.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The temporary top, in bytes.
Note
The top as the word holds it. A trim a give left owed on the open word does not run here; mmgr_buf_available and the next take run it.

Definition at line 528 of file locus_carcerum.h.

References SeriesCellularum::bounds, MMGR_CARCER_HALF_BITS, and mmgr_series_cellularum_temporary_top().

Referenced by mmgr_series_cellularum_idle(), and mmgr_series_cellularum_temporary_top().

◆ mmgr_series_cellularum_idle()

embed_bool mmgr_series_cellularum_idle ( const SeriesCellularum * series)
inlinestatic

Whether no cell is taken from a cellblock.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
EMBED_TRUE where both tiers stand empty.

Definition at line 540 of file locus_carcerum.h.

References mmgr_series_cellularum_idle(), mmgr_series_cellularum_persistent_end(), mmgr_series_cellularum_temporary_top(), and SeriesCellularum::size.

Referenced by mmgr_series_cellularum_idle().

◆ mmgr_series_cellularum_persistent_hw()

size_t mmgr_series_cellularum_persistent_hw ( const SeriesCellularum * series)
inlinestatic

The furthest a cellblock's persistent tier has reached.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The bytes, 0 where the build tracks none (MMGR_ENABLE_HW_MEM_CAPACITY_CB).

Definition at line 553 of file locus_carcerum.h.

References mmgr_series_cellularum_persistent_hw().

Referenced by mmgr_series_cellularum_persistent_hw().

◆ mmgr_series_cellularum_temporary_hw()

size_t mmgr_series_cellularum_temporary_hw ( const SeriesCellularum * series)
inlinestatic

The most bytes a cellblock's temporary tier has taken from the top.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The bytes, 0 where the build tracks none (MMGR_ENABLE_HW_MEM_CAPACITY_CB).

Definition at line 570 of file locus_carcerum.h.

References mmgr_series_cellularum_temporary_hw().

Referenced by mmgr_series_cellularum_temporary_hw().

◆ mmgr_persistent_buf_alloc()

void * mmgr_persistent_buf_alloc ( SeriesCellularum * series,
size_t size,
const CellOwner * owner )

Takes size bytes from a cellblock's persistent tier.

Parameters
[in,out]seriesCellblock to take from [BORROWS].
[in]sizeBytes wanted.
[in]ownerThe registered owner the cell is counted to [BORROWS].
Returns
Start of the cell, or NULL when owner is NULL or not registered or the cellblock cannot meet the take [RETURNS OWNERSHIP].
Note
Reached through the cellblock's own guard, never called by name.
A persistent cell stands until the same cellblock's persistent_buf_release takes it.
A cell handed out adds its payload bytes, the request rounded to a word, to owner's in_use and raises owner's hw to it. A refused take counts nothing.
The take is one pass through the cellblock's turnstiles and one fetch-add on the persistent end: the cell is the bytes the bump covered, and its header and owner word are laid once the room is read off the top. A bump the gap cannot meet adds its bytes to the tier's overrun and the take closes the cellblock, drains the turnstiles and walks the tier alone: every run of free cells merged into one, the first run that holds the take taken and split where its rest holds a cell, the free run reaching the end returned to the gap, and the gap bumped where no run fits. Only then is the take refused. No path branches on what another context did.
Warning
The bytes are not zeroed, and a cell laid over bytes a prisoner occupied before still carries what that prisoner left. A cellblock declared MMGR_MAXIMUM_SECURITY zeroes, and it zeroes on release.

References MMGR_ALLOC_SIZE, and mmgr_persistent_buf_alloc().

Referenced by mmgr_persistent_buf_alloc().

◆ mmgr_persistent_max_security_buf_alloc()

void * mmgr_persistent_max_security_buf_alloc ( SeriesCellularum * series,
size_t size,
const CellOwner * owner )

Takes size bytes from a maximum security cellblock's persistent tier.

Parameters
[in,out]seriesCellblock to take from [BORROWS].
[in]sizeBytes wanted.
[in]ownerThe registered owner the cell is counted to [BORROWS].
Returns
As mmgr_persistent_buf_alloc answers [RETURNS OWNERSHIP].
Note
The take mmgr_persistent_buf_alloc makes. A maximum security cellblock zeroes on release.

References mmgr_persistent_max_security_buf_alloc().

Referenced by mmgr_persistent_max_security_buf_alloc().

◆ mmgr_persistent_buf_release()

void mmgr_persistent_buf_release ( SeriesCellularum * series,
void * prisoner,
const CellOwner * owner )

Releases a prisoner, leaving the cell's bytes as they are.

Parameters
[in,out]seriesCellblock the prisoner came from [BORROWS].
[in]prisonerFirst byte of the cell [TAKES OWNERSHIP].
[in]ownerThe owner the cell counts to, as its owner word names it [BORROWS].
Note
Which tier the cell lies in is read from its offset against the persistent end. A NULL prisoner or a NULL owner changes nothing.
The give is one fetch-or on the cell's owner word, which sets its completion bit, and one store on the cell's header, which goes free: the cell's payload bytes, read off its header, come off owner's in_use in the context whose fetch-or found the bit clear. A release naming an owner other than the cell's changes nothing and is told through mmgr_carcer_hw_misnamed; one of a cell given back already changes nothing either. No pass and no wait: the cell's words are its holder's alone.
A free cell stays in its tier for the compaction a take the gap cannot meet runs, which merges it with its free neighbors, takes it where it fits, or returns it to the gap where it reaches the end.
Warning
A prisoner outside this cellblock's own bytes stops the program with MMGR_FATAL: there is no state to carry on from.
prisoner is dead once this returns and its bytes are not zeroed. The cellblock may hand them out again.
The bound is the cellblock's storage and never a cell boundary. An address inside these bytes that is not the first byte of a cell is still read as a cell's word.

References mmgr_persistent_buf_release().

Referenced by mmgr_persistent_buf_release().

◆ mmgr_persistent_max_security_buf_release()

void mmgr_persistent_max_security_buf_release ( SeriesCellularum * series,
void * prisoner,
const CellOwner * owner )

Zeroes a cell, then releases the prisoner.

Parameters
[in,out]seriesCellblock the prisoner came from [BORROWS].
[in,out]prisonerFirst byte of the cell, zeroed before release [TAKES OWNERSHIP].
[in]ownerThe owner the cell counts to, as its owner word names it [BORROWS].
Note
The extent comes from the cell's own header. A caller cannot under-zero a cell by naming fewer bytes than it carries. A NULL prisoner or a NULL owner changes nothing.
The zeroing is the only step that separates this from mmgr_persistent_buf_release, and it runs once the owner named is found to be the cell's and the cell still counted: a release naming another owner, or of a cell given back already, zeroes nothing.
Warning
A prisoner outside this cellblock's own bytes stops the program with MMGR_FATAL.
prisoner is dead once this returns. The cellblock may hand those bytes out again.
The bound is the cellblock's storage and never a cell boundary. An address inside these bytes that is not the first byte of a cell still has its extent read from the bytes ahead of it, and is zeroed for whatever length those hold.

References mmgr_persistent_max_security_buf_release().

Referenced by mmgr_persistent_max_security_buf_release().

◆ mmgr_buf_grow()

void * mmgr_buf_grow ( SeriesCellularum * series,
void * prisoner,
size_t size,
const CellOwner * owner )

Grows a cell to size payload bytes in place, where it is the newest cell of its tier.

Parameters
[in,out]seriesCellblock the prisoner came from [BORROWS].
[in,out]prisonerFirst byte of the cell [BORROWS].
[in]sizePayload bytes the cell is to carry, rounded as a take rounds them.
[in]ownerThe owner the cell counts to, as its owner word names it, which the growth is counted to [BORROWS].
Returns
The cell's first byte after the growth: the prisoner itself for a persistent cell, or for one that carries size already; a lower address for a temporary cell, whose bytes moved down. NULL with nothing changed where the cell is not the newest of its tier, a cell having been taken above it since, or where the gap cannot meet the growth. A NULL prisoner, a NULL owner, or an owner other than the cell's, which is told through mmgr_carcer_hw_misnamed, returns NULL [RETURNS OWNERSHIP].
Note
The growth closes the cellblock, drains the turnstiles and works alone. The newest cell of a tier is the cell its boundary stands against: the persistent end at the cell's end, the temporary top at the cell's header. The gap is read exactly, the boundary stored past the growth, and no other cell moves. A caller whose growth is refused takes a larger cell, copies into it and releases the first, as it would without this entry.
The added bytes are as they lie: a persistent growth's hold the word that stood behind the payload, a temporary growth's the cell's own old header and payload. mmgr_max_security_buf_grow zeroes them.
Warning
The prisoner's address is dead after a temporary growth that answers a lower one: the cell is reached at the address answered from then on. A prisoner outside this cellblock's own bytes stops with MMGR_FATAL, as a release does.

References MMGR_ALLOC_SIZE, and mmgr_buf_grow().

Referenced by mmgr_buf_grow().

◆ mmgr_max_security_buf_grow()

void * mmgr_max_security_buf_grow ( SeriesCellularum * series,
void * prisoner,
size_t size,
const CellOwner * owner )

Grows a cell in place as mmgr_buf_grow does, and zeroes the bytes the growth adds.

Parameters
[in,out]seriesCellblock the prisoner came from [BORROWS].
[in,out]prisonerFirst byte of the cell [BORROWS].
[in]sizePayload bytes the cell is to carry.
[in]ownerThe owner a persistent cell's growth is counted to [BORROWS].
Returns
As mmgr_buf_grow answers [RETURNS OWNERSHIP].
Note
The zeroing covers the growth's bytes alone: the payload the cell carried keeps its bytes, moved for a temporary cell.

References mmgr_max_security_buf_grow().

Referenced by mmgr_max_security_buf_grow().

◆ mmgr_temporary_buf_alloc()

void * mmgr_temporary_buf_alloc ( SeriesCellularum * series,
size_t size,
const CellOwner * owner )

Takes size bytes from a cellblock's temporary tier.

Parameters
[in,out]seriesCellblock to take from [BORROWS].
[in]sizeBytes wanted.
[in]ownerThe registered owner the cell is counted to [BORROWS].
Returns
Start of the cell, or NULL when owner is NULL or not registered or the cellblock cannot meet the take [RETURNS OWNERSHIP].
Note
The caller gives the cell back through mmgr_persistent_buf_release, as a persistent cell is given back, which takes the bytes off owner. The cell carries owner in the word behind its payload.
The take is mmgr_persistent_buf_alloc's with the arithmetic mirrored: one pass through the cellblock's turnstiles and one fetch-add on the temporary top, which moves it down by the cell; the room is read off the persistent end, and a bump that crosses it adds its bytes to the tier's overrun. The take then closes the cellblock, drains the turnstiles and walks the tier alone: every run of free cells merged into one, the fitting run nearest the cellblock's size taken and split where its rest holds a cell, the free run at the top returned to the gap, and the top bumped where no run fits. Only then is the take refused.
Warning
The bytes are not zeroed, and an allocation returns whatever the last prisoner left. A cellblock declared MMGR_MAXIMUM_SECURITY zeroes, and it zeroes on release.

References MMGR_ALLOC_SIZE, and mmgr_temporary_buf_alloc().

Referenced by mmgr_temporary_buf_alloc().

◆ mmgr_temporary_max_security_buf_alloc()

void * mmgr_temporary_max_security_buf_alloc ( SeriesCellularum * series,
size_t size,
const CellOwner * owner )

Takes size bytes from a maximum security cellblock's temporary tier.

Parameters
[in,out]seriesCellblock to take from [BORROWS].
[in]sizeBytes wanted.
[in]ownerThe registered owner the cell is counted to [BORROWS].
Returns
As mmgr_temporary_buf_alloc answers [RETURNS OWNERSHIP].
Note
The take mmgr_temporary_buf_alloc makes. A maximum security cellblock zeroes on release.

References mmgr_temporary_max_security_buf_alloc().

Referenced by mmgr_temporary_max_security_buf_alloc().

◆ mmgr_who_owns_buf()

embed_bool mmgr_who_owns_buf ( const SeriesCellularum * series,
const void * at )

Whether at lies inside the cellblock's bytes.

Parameters
[in]seriesCellblock to test against [BORROWS].
[in]atAddress to test [BORROWS].
Returns
EMBED_TRUE when at lies in the cellblock's storage, which is [base, base + size).
Note
One unsigned compare covers both ends, since an address below base wraps to a difference larger than any size.
Warning
Any address in the cellblock answers true, the first byte of a cell or any other. This says where an address is and nothing of what is there. A true answer is not a warrant that at may be released. The releases read a cell's word from whatever address they are handed.

References mmgr_who_owns_buf().

Referenced by mmgr_who_owns_buf().

◆ mmgr_owner_of_buf()

const CellOwner * mmgr_owner_of_buf ( const SeriesCellularum * series,
const void * prisoner )

The owner a cell counts to, read off the word behind its payload.

Parameters
[in]seriesCellblock the prisoner came from [BORROWS].
[in]prisonerFirst byte of the cell [BORROWS].
Returns
The registered owner the cell's owner word names, or NULL where prisoner is NULL, lies outside the cellblock, is a cell no context holds, or its word names no registered owner [BORROWS].
Note
A holder that grows or gives back a cell another part of the program took, a line that grows in the hands of whoever is writing it, names the owner this answers.
Warning
The bound is the cellblock's storage and never a cell boundary, as for a release: an address inside these bytes that is not the first byte of a cell is read as a cell's word.

References mmgr_owner_of_buf().

Referenced by mmgr_owner_of_buf().

◆ mmgr_buf_available()

size_t mmgr_buf_available ( SeriesCellularum * series)

The bytes lying between the two tiers.

Parameters
[in,out]seriesCellblock to read [BORROWS].
Returns
The temporary top less the persistent end, read off one word.
Note
An allocation out of that gap needs a cell header from the same bytes, and the request is rounded up to a whole word first. A request of exactly this many bytes cannot be met.
The trims a give left owed on the open word run first, and the gap read has every owed trim run.
Warning
The answer is a snapshot. Any allocation at all leaves it stale before the caller can act on it.

References mmgr_buf_available().

Referenced by mmgr_buf_available().

◆ mmgr_zero_buf()

void mmgr_zero_buf ( void * prisoner,
size_t size )

Zeroes size bytes at prisoner, releasing nothing.

Parameters
[in,out]prisonerFirst byte to clear [BORROWS].
[in]sizeBytes to clear.
Note
The stores are volatile: clearing bytes nothing reads afterwards is not dropped as dead work. The middle is stored a word at a time, the two edges a byte at a time.
The extent is the caller's to state. A zeroing release takes it from the cell's own word.
Warning
prisoner must be writable for size bytes.

References mmgr_zero_buf().

Referenced by mmgr_zero_buf().

◆ mmgr_align_up_buf()

size_t mmgr_align_up_buf ( size_t size)

Rounds size up to a whole machine word.

Parameters
[in]sizeCount to round.
Returns
size rounded up to a multiple of MMGR_CARCER_ALIGN, and size itself when it already is one.
Note
A size of 0 rounds to 0. The allocators do not round a request this way. They carry a request of 0 up to one word first: no cell is handed out empty.
Warning
MMGR_CARCER_ALIGN - 1 is added before the mask. A size within a word of SIZE_MAX wraps to 0.

References mmgr_align_up_buf().

Referenced by mmgr_align_up_buf().

◆ mmgr_series_cellularum_emptied()

void mmgr_series_cellularum_emptied ( SeriesCellularum * series)

Puts a cellblock back to the state it was declared in: both tiers empty, the closed word and the turnstiles at rest, the option unassigned, and no byte of its storage touched.

Parameters
[in,out]seriesCellblock to empty [BORROWS].
Note
Every cell the cellblock has handed out is dead once this returns. A suite calls it between cases over one declared cellblock; a program with a cellblock to empty while another context reaches it has a cellblock whose cells that context still holds.
Nothing outside the tiers is read as a cell, and so no cell's words are touched.

References mmgr_series_cellularum_emptied().

Referenced by mmgr_series_cellularum_emptied().

◆ mmgr_owner_bytes_taken()

void mmgr_owner_bytes_taken ( const CellOwner * owner,
size_t bytes )

Counts bytes that lie in no cellblock to an owner, as a ring's or a page's are.

Parameters
[in]ownerThe registered owner [BORROWS].
[in]bytesThe bytes.
Note
An owner's counts are the program's running total, and memory a program takes outside a cellblock belongs in it. No cellblock's own running total moves.

References mmgr_owner_bytes_taken().

Referenced by mmgr_owner_bytes_taken().

◆ mmgr_owner_bytes_given()

void mmgr_owner_bytes_given ( const CellOwner * owner,
size_t bytes )

Takes bytes mmgr_owner_bytes_taken counted off their owner.

Parameters
[in]ownerThe owner they were counted to [BORROWS].
[in]bytesThe bytes.

References mmgr_owner_bytes_given().

Referenced by mmgr_owner_bytes_given().

◆ mmgr_series_cellularum_fragmentation()

size_t mmgr_series_cellularum_fragmentation ( const SeriesCellularum * series)

A cellblock's fragmentation: the bytes its persistent tier occupies and no cell's payload holds, as a percentage of the bytes it occupies.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The percentage, 0 to 100, read against the hundredth of the bytes occupied rounded up, and 0 below a hundred bytes occupied.
Note
Read off the persistent end and the tier's running total, with no walk. Each cell's words count among the bytes no payload holds, and a tier of small cells reads some fragmentation with no free cell.
The temporary tier reads nothing: its cells last one call, and its top comes back as they end. A free cell no movable cell stands above is no work for a mover either: a sort that finds nothing to move is remembered, and not run again until the reading rises.

References mmgr_series_cellularum_fragmentation().

Referenced by mmgr_series_cellularum_fragmentation().

◆ mmgr_movable_init()

embed_bool mmgr_movable_init ( SeriesCellularum * series,
const CarcerMovableInitCfg * args,
embed_bool wipes )

Assigns a cellblock's movable option: the translation table, its claim bits, the rows of touches and the mover's thread. A cellblock's guard calls this, as movable_init.

Parameters
[in,out]seriesCellblock the option serves [BORROWS].
[in]argsThe storage, the sizes and the thread's calls [BORROWS].
[in]wipesWhether a cell a move leaves or a release gives back is zeroed first.
Returns
EMBED_TRUE where the option is assigned and, where a thread was given, the thread started. EMBED_FALSE where it is assigned already, the storage is short or a size is zero, nothing changed, or where the thread did not start, which leaves the option assigned and nothing moving a cell.
Note
Assigned once, at a time no context reaches a movable cell. The cellblock's turnstiles are what the mover reads as occupancy: the lanes open against the option's width.

References mmgr_movable_init().

Referenced by mmgr_movable_init().

◆ mmgr_movable_buf_alloc()

const CarcerMovableEntry * mmgr_movable_buf_alloc ( SeriesCellularum * series,
size_t size,
const CellOwner * owner )

Takes a persistent cell a move may move, and names it in the table.

Parameters
[in,out]seriesCellblock to take from [BORROWS].
[in]sizeBytes wanted.
[in]ownerThe registered owner the cell is counted to [BORROWS].
Returns
The cell's identity, or NULL where the option is not assigned, the cellblock cannot meet the take or the table has no free entry, nothing counted.
Note
The identity is a const pointer to the cell's entry. It stands for the cell's life whatever moves the cell, and the movable_buf_ calls are the only way from it to the bytes.
Warning
A pointer kept past mmgr_movable_buf_release names an entry a later take may reuse.

References mmgr_movable_buf_alloc().

Referenced by mmgr_movable_buf_alloc().

◆ mmgr_movable_buf_release()

embed_bool mmgr_movable_buf_release ( SeriesCellularum * series,
const CarcerMovableEntry * cell,
const CellOwner * owner )

Gives a movable cell back and frees its entry.

Parameters
[in,out]seriesCellblock the cell is in [BORROWS].
[in]cellThe cell [BORROWS].
[in]ownerThe owner the cell is counted to [BORROWS].
Returns
EMBED_TRUE where it went back. EMBED_FALSE where cell is NULL, the entry is free or owner is not the cell's, which mmgr_carcer_hw_misnamed is told of, nothing changed.
Note
One pass through the cellblock's turnstiles: the entry read, the cell given back as a release gives it, the entry's word and its claim bit cleared. A move is a writer, which drains the passes before it and closes the cellblock to those after: the two never reach the entry at once.

References mmgr_movable_buf_release().

Referenced by mmgr_movable_buf_release().

◆ mmgr_movable_buf_read()

embed_bool mmgr_movable_buf_read ( const SeriesCellularum * series,
const CarcerMovableCfg * args )

Copies args->bytes from args->offset of a movable cell to args->dst.

Parameters
[in,out]seriesCellblock the cell is in [BORROWS].
[in]argsThe cell, offset, dst and bytes [BORROWS].
Returns
EMBED_TRUE where copied, EMBED_FALSE where the span passes the cell's end or the entry is free, nothing copied.
Note
Thin: one pass through the cellblock's turnstiles, badged with the calling thread's id, the entry's word read, the bytes copied, and the lane let go. A pass that finds the cellblock closed to a move backs off one step and tries once more.

References mmgr_movable_buf_read().

Referenced by mmgr_movable_buf_read().

◆ mmgr_movable_buf_write()

embed_bool mmgr_movable_buf_write ( SeriesCellularum * series,
const CarcerMovableCfg * args )

Copies args->bytes from args->src to args->offset of a movable cell.

Parameters
[in,out]seriesCellblock the cell is in [BORROWS].
[in]argsThe cell, offset, src and bytes [BORROWS].
Returns
As mmgr_movable_buf_read answers.
Note
Atomic against a move and not against another writer: two contexts writing the same bytes order themselves.

References mmgr_movable_buf_write().

Referenced by mmgr_movable_buf_write().

◆ mmgr_movable_buf_compare()

embed_iword mmgr_movable_buf_compare ( const SeriesCellularum * series,
const CarcerMovableCfg * args )

Orders args->bytes of a movable cell against args->src, or against another cell where args->other_cell is set.

Parameters
[in,out]seriesCellblock the cell is in [BORROWS].
[in]argsThe cell, offset, and src or other_cell and other_offset, and bytes [BORROWS].
Returns
As memor.cmp orders them, and 1 where a span passes its cell's end or an entry is free.
Note
Two cells are the most one call reaches, both read under the one pass.

References mmgr_movable_buf_compare().

Referenced by mmgr_movable_buf_compare().

◆ mmgr_movable_buf_measure()

size_t mmgr_movable_buf_measure ( const SeriesCellularum * series,
const CarcerMovableCfg * args )

The bytes from args->offset of a movable cell to the next zero byte.

Parameters
[in,out]seriesCellblock the cell is in [BORROWS].
[in]argsThe cell and offset [BORROWS].
Returns
The bytes, or the bytes to the cell's end where no zero stands before it.

References mmgr_movable_buf_measure().

Referenced by mmgr_movable_buf_measure().

◆ mmgr_movable_buf_move()

embed_bool mmgr_movable_buf_move ( SeriesCellularum * series)

Moves one movable cell into the first free cell below it, highest cell first.

Parameters
[in,out]seriesCellblock whose cells to move [BORROWS].
Returns
EMBED_TRUE where a cell moved. EMBED_FALSE where none could at this reading: no free run fits below any of them.
Note
The mover's step, a writer's: the cellblock closed and the turnstiles drained, the highest named cell read, the persistent tier walked below it for the first free run that holds it, the cell copied, its owner word carried over, the entry flipped to the copy, the cell left behind set free, and the cellblock opened. The same state moves the same cell to the same place.
Called until it answers EMBED_FALSE, the cells stand as low as the free runs let them, and the free run reaching the tier's end returns to the gap with each walk.
The copy carries the cell's owner word, and so the owner's count stands as it was through the move.
A cell no free run below takes rules out every cell at least its size lying under it, since those look through the same free runs for as much room.
Warning
Each cell moved, and each smaller size refused, costs a read of the named part of the table and a walk of the tier below the cell.

References mmgr_movable_buf_move().

Referenced by mmgr_movable_buf_move().

◆ mmgr_movable_run()

void mmgr_movable_run ( SeriesCellularum * series)

The mover: what the thread the program gave runs, until its thread_wait answers EMBED_FALSE.

Parameters
[in,out]seriesCellblock with the option assigned and thread_wait given [BORROWS].
Note
Each MMGR_MOVABLE_READ_MS it reads the cellblock. Fragmentation under MMGR_MOVABLE_SETTLE_PERCENT ends the reading. Over it, MMGR_MOVABLE_QUIET_READINGS in a row must find the cellblock quiet: twice the lanes its turnstiles have open at or under the option's width plus one, and no pass through them since the last reading. It then moves cells one at a time, the cellblock open and the processor yielded between moves, and reads the same after each: a pass, or lanes open past quiet, says the moves meet pressure, and it backs off.
Backing off doubles the wait, up to MMGR_MOVABLE_BACKOFF_MOST_MS. A sort that ends with nothing left to move resets the wait, and the fragmentation it left is remembered: nothing is run again until the reading rises past that or falls under the threshold first.

References mmgr_movable_run().

Referenced by mmgr_movable_run().

◆ mmgr_movable_queue_depth()

size_t mmgr_movable_queue_depth ( const SeriesCellularum * series)

The contexts queued at the cellblock's turnstiles now: those that found every open lane busy and wait for a lane.

Parameters
[in]seriesCellblock to read [BORROWS].
Returns
The queued contexts, 0 without the option.

References mmgr_movable_queue_depth().

Referenced by mmgr_movable_queue_depth().

◆ mmgr_movable_touches()

embed_bool mmgr_movable_touches ( const SeriesCellularum * series,
size_t at,
size_t * id,
size_t * touches )

One row of touches a lane, counted as passes go through it.

Parameters
[in,out]seriesCellblock to read [BORROWS].
[in]atThe row, from 0: the lane of the same place.
[out]idThe id of the last badge through the lane: an owner's place, or a thread's id plus one for a pass naming no owner [BORROWS].
[out]touchesThe passes through the lane so far [BORROWS].
Returns
EMBED_TRUE where the row holds a lane's passes, EMBED_FALSE past the rows in use or for a lane no pass has gone through.
Note
A telemetry row, counted by one add as each pass badges in, and nothing decides on it. The option's last row counts every lane past the rest, and answers an id of SIZE_MAX.

References mmgr_movable_touches().

Referenced by mmgr_movable_touches().

Variable Documentation

◆ mmgr_owner_table

CellOwner mmgr_owner_table[]
extern

The program's owner table and the owners in it, which MMGR_OWNERS defines once.

Note
A program that reaches a cellblock declares its owners with MMGR_OWNERS in one translation unit; a build with none fails at the link, naming these.

Referenced by mmgr_carcer_hw_clock_ns().