memory_arena
Loading...
Searching...
No Matches
arena_tlscratch.c
Go to the documentation of this file.
1
114#include "arena.h"
115
116#if ARENA_ENABLE_THREAD_LOCAL_SCRATCH
117
144_Thread_local static t_arena thread_scratch_arena;
145_Thread_local static bool thread_scratch_initialized = false;
146_Thread_local static size_t thread_scratch_size = 8192;
147
176void set_thread_scratch_arena_size(size_t size)
177{
178 if (!thread_scratch_initialized)
179 thread_scratch_size = size;
180}
181
211{
212 return &thread_scratch_arena;
213}
214
245{
246 if (!thread_scratch_initialized)
247 {
248 arena_init(&thread_scratch_arena, 8192, true);
249 thread_scratch_initialized = true;
250 }
251 arena_reset(&thread_scratch_arena);
252 return &thread_scratch_arena;
253}
254
279{
280 if (thread_scratch_initialized)
281 {
282 arena_destroy(&thread_scratch_arena);
283 thread_scratch_initialized = false;
284 }
285}
286
287#else
288
290{
291 arena_report_error(NULL, "get_thread_scratch_arena() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
292 return NULL;
293}
294
296{
297 arena_report_error(NULL, "destroy_thread_scratch_arena() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
298}
299
301{
302 (void)size;
303 arena_report_error(NULL, "set_thread_scratch_arena_size() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is "
304 "disabled");
305}
306
308{
309 arena_report_error(NULL, "get_thread_scratch_arena_ref() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
310 return NULL;
311}
312
313#endif
Core public API for the Arena memory allocator.
void arena_reset(t_arena *arena)
bool arena_init(t_arena *arena, size_t size, bool allow_grow)
void arena_destroy(t_arena *arena)
void arena_report_error(t_arena *arena, const char *fmt,...)
Report an error from an arena using its configured error callback.
void destroy_thread_scratch_arena(void)
Destroy the thread-local scratch arena for the calling thread.
t_arena * get_thread_scratch_arena(void)
Get the thread-local scratch arena, resetting it before use.
t_arena * get_thread_scratch_arena_ref(void)
Access the raw thread-local arena pointer without initialization.
void set_thread_scratch_arena_size(size_t size)
Configure the initial size for the thread-local scratch arena.
The main memory arena structure used for fast allocation.