30#ifndef PROTOCORE_ARENA_H
31#define PROTOCORE_ARENA_H
37#define PC_ARENA_ALIGN 8u
46#define PC_ARENA_MAX_ALIGN 16u
125 size_t nt = (a->
scratch_top - n) & ~(
size_t)(align - 1);
185 const uint8_t *q = (
const uint8_t *)p;
215#ifndef PC_ARENA_MAX_REGIONS
216#define PC_ARENA_MAX_REGIONS 2u
size_t pc_arena_set_scratch_used(const pc_arena_set *s)
Scratch bytes allocated, summed over all regions.
void pc_arena_scratch_reset(pc_arena *a)
Free ALL scratch allocations in O(1).
void * pc_arena_set_scratch_alloc_aligned(pc_arena_set *s, size_t n, size_t align)
Aligned scratch alloc from the first region that fits (see pc_arena_scratch_alloc_aligned()).
bool pc_arena_set_add(pc_arena_set *s, void *base, size_t size)
Add a region [base, base+size); regions are searched in the order added.
void * pc_arena_scratch_alloc(pc_arena *a, size_t n)
Bump-allocate n transient bytes at the baseline alignment (PC_ARENA_ALIGN).
void * pc_arena_set_scratch_alloc(pc_arena_set *s, size_t n)
Scratch alloc from the first region that fits (see pc_arena_scratch_alloc()).
size_t pc_arena_set_persist_used(const pc_arena_set *s)
Persistent payload bytes allocated, summed over all regions.
void pc_arena_set_scratch_reset(pc_arena_set *s)
Reset scratch in every region.
size_t pc_arena_align_up(size_t n)
Round n up to PC_ARENA_ALIGN.
#define PC_ARENA_MAX_ALIGN
Strongest alignment a scratch borrow may request; the region base is aligned to it.
size_t pc_arena_scratch_mark(const pc_arena *a)
Capture the current scratch position (a savepoint for pc_arena_scratch_release()).
void pc_arena_set_persist_free(pc_arena_set *s, void *p)
Free a persistent pointer, routed to its owning region by address.
#define PC_ARENA_ALIGN
Baseline alignment (bytes) applied to every allocation and to headers.
void pc_arena_set_scratch_release(pc_arena_set *s, const pc_arena_mark *m)
Restore every region's scratch position to m (frees scratch made since).
#define PC_ARENA_MAX_REGIONS
Max regions in a pc_arena_set (DRAM base + PSRAM extension).
void pc_arena_scratch_release(pc_arena *a, size_t mark)
Free every scratch allocation made since mark (a value from pc_arena_scratch_mark()).
pc_arena_mark pc_arena_set_scratch_mark(const pc_arena_set *s)
Capture the scratch position of every region.
void pc_arena_persist_free(pc_arena *a, void *p)
Free a pointer previously returned by pc_arena_persist_alloc().
size_t pc_arena_free_bytes(const pc_arena *a)
Free bytes in the middle (max a single new allocation could take, minus a header).
void * pc_arena_scratch_alloc_aligned(pc_arena *a, size_t n, size_t align)
Bump-allocate n bytes of transient storage, aligned to align.
size_t pc_arena_scratch_used(const pc_arena *a)
Scratch bytes currently allocated.
void * pc_arena_set_persist_alloc(pc_arena_set *s, size_t n)
Persistent alloc from the first region that fits (see pc_arena_persist_alloc()).
void pc_arena_set_init(pc_arena_set *s)
Initialize an empty set (no regions yet).
size_t pc_arena_persist_used(const pc_arena *a)
Persistent payload bytes currently allocated.
void * pc_arena_persist_alloc(pc_arena *a, size_t n)
Allocate n zero-initialized bytes of long-lived storage.
void pc_arena_init(pc_arena *a, void *base, size_t size)
Initialize a over the region [base, base+size).
size_t pc_arena_set_free_bytes(const pc_arena_set *s)
Total free middle bytes summed over all regions.
bool pc_arena_owns(const pc_arena *a, const void *p)
True if p points inside this pool's region.
A scratch savepoint across every region of a pc_arena_set.
A set of pc_arena regions searched in insertion (preference) order.
size_t count
Regions in use.
Double-ended arena over one region [base, base+size).
size_t persist_used
Bytes currently handed out by the persistent pool (payload).
size_t scratch_top
Scratch occupies [scratch_top, size).
uint8_t * base
Region start.
size_t scratch_hw
High-water of scratch use (size - min scratch_top).
size_t persist_hw
High-water of persist_end (for sizing).
size_t size
Region length in bytes.
size_t persist_end
Persistent pool occupies [0, persist_end).