cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
arena.c File Reference

Request-scoped arena allocator built on libttak arena generations. More...

#include <cwist/core/mem/arena.h>
#include <cwist/sys/platform.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
Include dependency graph for arena.c:

Go to the source code of this file.

Functions

cwist_arena_t * cwist_arena_create (size_t generation_bytes)
 Create an arena backed by a recycled thread-local generation buffer.
 
void * cwist_arena_alloc (cwist_arena_t *arena, size_t size)
 Bump-allocate size bytes from the active generation.
 
bool cwist_arena_owns (const cwist_arena_t *arena, const void *ptr)
 Check whether ptr lies inside the active generation buffer.
 
void cwist_arena_destroy (cwist_arena_t *arena)
 Retire the generation and destroy the arena, releasing every allocation made from it at once.
 

Detailed Description

Request-scoped arena allocator built on libttak arena generations.

Performance notes:

  • Generation buffers are recycled through a per-thread free list, so the steady-state request cycle performs no libttak mem-tree registration or epoch-GC work at all; ttak_mem_alloc/free is only touched when the cache underflows/overflows (thread start or concurrency watermark changes).
  • The ttak_arena_env_t (epoch/GC coordinator) lives in thread-local storage and is initialized once per thread, never per request.
  • Cleanup on thread exit is handled through a pthread key destructor, which keeps this file portable C11/POSIX with no architecture-specific code.

Definition in file arena.c.

Function Documentation

◆ cwist_arena_alloc()

void * cwist_arena_alloc ( cwist_arena_t *  arena,
size_t  size 
)

Bump-allocate size bytes from the active generation.

Returns
Aligned chunk, or NULL when the generation is exhausted (callers should fall back to cwist_alloc).
Note
The returned memory is NOT zeroed.

Definition at line 44 of file arena.c.

◆ cwist_arena_create()

cwist_arena_t * cwist_arena_create ( size_t  generation_bytes)

Create an arena backed by a recycled thread-local generation buffer.

Parameters
generation_bytesCapacity of the generation buffer (0 = default).
Returns
New arena, or NULL on failure (callers should fall back to heap).
Note
Default-sized buffers come from a per-thread recycle cache, so steady-state creation triggers no libttak GC/mem-tree activity.

Definition at line 32 of file arena.c.

References CWIST_ARENA_DEFAULT_GENERATION_BYTES.

Referenced by cwist_http_request_create(), and cwist_http_response_create().

◆ cwist_arena_destroy()

void cwist_arena_destroy ( cwist_arena_t *  arena)

Retire the generation and destroy the arena, releasing every allocation made from it at once.

Definition at line 60 of file arena.c.

Referenced by cwist_http_request_create(), cwist_http_request_destroy(), cwist_http_response_create(), and cwist_http_response_destroy().

◆ cwist_arena_owns()

bool cwist_arena_owns ( const cwist_arena_t *  arena,
const void *  ptr 
)

Check whether ptr lies inside the active generation buffer.

Definition at line 54 of file arena.c.

Referenced by cwist_http_request_destroy(), and cwist_http_response_destroy().