31#ifndef ARENA_SCRATCH_H
32#define ARENA_SCRATCH_H
41#define SCRATCH_MAX_SLOTS 64
44#ifdef ARENA_ENABLE_THREAD_SAFE
45#define SCRATCH_LOCK(pool) \
46 if ((pool)->thread_safe) \
47 pthread_mutex_lock(&(pool)->lock)
50#define SCRATCH_UNLOCK(pool) \
51 if ((pool)->thread_safe) \
52 pthread_mutex_unlock(&(pool)->lock)
54#define SCRATCH_LOCK(pool) ((void) 0)
55#define SCRATCH_UNLOCK(pool) ((void) 0)
Core public API for the Arena memory allocator.
#define SCRATCH_MAX_SLOTS
Maximum number of concurrently usable scratch arenas in the pool.
atomic_bool in_use
Atomic flag for acquisition tracking.
t_arena arena
Memory arena associated with this slot.
struct s_scratch_slot t_scratch_slot
Represents a single slot in the scratch arena pool.
Represents a single slot in the scratch arena pool.
size_t slot_size
Size of each arena in bytes.
pthread_mutex_t lock
Mutex for protecting slot access.
t_scratch_slot slots[SCRATCH_MAX_SLOTS]
Array of scratch slots.
bool thread_safe
Whether locking is enabled.
void scratch_pool_destroy(t_scratch_arena_pool *pool)
Destroy all arenas in a scratch pool and reset its metadata.
t_arena * scratch_acquire(t_scratch_arena_pool *pool)
Acquire a temporary scratch arena from the pool.
struct s_scratch_arena_pool t_scratch_arena_pool
Scratch arena pool structure holding multiple reusable memory arenas.
bool scratch_pool_init(t_scratch_arena_pool *pool, size_t slot_size, bool thread_safe)
Initialize a scratch arena pool with pre-allocated slots.
void scratch_release(t_scratch_arena_pool *pool, t_arena *arena)
Release a scratch arena back to the pool for reuse.
Scratch arena pool structure holding multiple reusable memory arenas.
The main memory arena structure used for fast allocation.