43struct PlainPoolStorageCtx
49PlainPoolStorageCtx s_plain_storage;
59inline uintptr_t plain_offset(
const void *p)
61 return (uintptr_t)p - (uintptr_t)s_plain_storage.mem;
66inline int cur_worker()
76inline void assert_single_owner(
int w)
90 assert(s_owner[w] == cur &&
"plaintext pool borrowed from a foreign task");
102 if (a->
base ==
nullptr)
114 return (a->
base !=
nullptr) ? a :
nullptr;
121 int w = cur_worker();
122 assert_single_owner(w);
130 int w = cur_worker();
131 assert_single_owner(w);
137 int w = cur_worker();
138 assert_single_owner(w);
142 assert((align & (align - 1)) == 0 &&
"scratch alignment must be a power of two");
156 int w = cur_worker();
157 assert_single_owner(w);
167 int w = cur_worker();
168 assert_single_owner(w);
174 int w = cur_worker();
175 assert_single_owner(w);
181 const pc_arena *a = peek(cur_worker());
208 return plain_offset(p) < (uintptr_t)
sizeof(s_plain_storage.mem);
213 const uintptr_t off = plain_offset(p);
214 if (off >= (uintptr_t)
sizeof(s_plain_storage.mem))
void pc_arena_init(pc_arena *a, void *base, size_t size)
Initialize a over the region [base, base+size).
Unified double-ended server arena (Phase 1: core allocator, one region).
void pc_arena_scratch_reset(pc_arena *a)
Free ALL scratch allocations in O(1).
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_scratch_release(pc_arena *a, size_t mark)
Free every scratch allocation made since mark (a value from pc_arena_scratch_mark()).
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.
#define PC_SCRATCH_ARENA_SIZE
ScratchBorrow(size_t n, size_t align)
size_t scratch_mark(void)
Capture the current arena offset (a savepoint for scratch_release()).
pc_span pc_scratch_span(size_t n, size_t align)
Borrow n bytes as a span whose capacity is bound to the allocation.
bool pc_scratch_owns(const void *p)
True if p points inside the plaintext pool.
size_t scratch_capacity(void)
Total arena capacity in bytes (PC_SCRATCH_ARENA_SIZE).
void * scratch_alloc(size_t n, size_t align)
Borrow n bytes of scratch, aligned to align.
int pc_scratch_slot_of(const void *p)
Which plaintext slot owns p, or -1 if p is not in the plaintext pool.
size_t scratch_used(void)
Bytes currently handed out (0 immediately after a reset).
size_t scratch_high_water(void)
Largest scratch_used() value seen since boot (for sizing the arena).
void scratch_reset(void)
Reclaim the whole arena (empties it).
void scratch_release(size_t mark)
Reclaim everything allocated since mark (LIFO).
Shared per-dispatch scratch arena (Layer 5, session-scoped memory).
pc_span pc_span_from(uint8_t *p, size_t cap)
Bind a span to memory whose extent is only known at run time.
Double-ended arena over one region [base, base+size).
uint8_t * base
Region start.
size_t scratch_hw
High-water of scratch use (size - min scratch_top).
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
int pc_worker_self(void)
Worker id [0, count) of the calling task; 0 by default / single-worker.
Layer 5 (Session) - server worker identity.