cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
session_manager.h File Reference

Request-scoped arena and shared-payload helpers for session data. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for session_manager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  session_rc_header
 Reference-count header placed immediately before shared session payloads. More...
 
struct  session_arena
 Linear arena used for fast request-lifetime allocations. More...
 
struct  session_manager
 Top-level session allocator state owned by a request context. More...
 

Functions

void session_arena_init (struct session_arena *arena, uint8_t *buffer, size_t capacity)
 Bind a caller-owned buffer to a session arena and reset its cursor.
 
void * session_arena_alloc (struct session_arena *arena, size_t size)
 Allocate aligned storage from the request arena.
 
void session_arena_reset (struct session_arena *arena)
 Reset the request arena so future allocations reuse the full buffer.
 
void session_rc_init (struct session_rc_header *header, void(*destructor)(void *))
 Initialize the metadata that tracks a shared session allocation.
 
void * session_shared_alloc (size_t payload_size, void(*destructor)(void *))
 Allocate a zeroed payload preceded by a reference-count header.
 
void session_shared_inc (void *payload)
 Increment the reference count for a shared payload.
 
void session_shared_dec (void *payload)
 Decrement the reference count and free the payload when it reaches zero.
 
void session_manager_init (struct session_manager *manager, uint8_t *buffer, size_t capacity)
 Initialize a session manager around a caller-supplied arena buffer.
 
void session_manager_reset (struct session_manager *manager)
 Reset all request-scoped allocations owned by the manager.
 

Detailed Description

Request-scoped arena and shared-payload helpers for session data.

Definition in file session_manager.h.

Function Documentation

◆ session_arena_alloc()

void * session_arena_alloc ( struct session_arena *  arena,
size_t  size 
)

Allocate aligned storage from the request arena.

Parameters
arenaArena to allocate from.
sizeRequested payload size in bytes.
Returns
Pointer to the reserved range, or NULL when capacity is exhausted.

Allocate aligned storage from the request arena.

Allocate from a session arena.

Parameters
arenaArena that owns the backing storage.
sizeNumber of bytes requested before alignment.
Returns
Pointer to a contiguous region, or NULL when the arena is exhausted.

Definition at line 30 of file session_manager.c.

◆ session_arena_init()

void session_arena_init ( struct session_arena *  arena,
uint8_t *  buffer,
size_t  capacity 
)

Bind a caller-owned buffer to a session arena and reset its cursor.

Parameters
arenaArena to initialize.
bufferBacking storage owned by the caller.
capacitySize of buffer in bytes.

Bind a caller-owned buffer to a session arena and reset its cursor.

Initialize a session arena.

Parameters
arenaArena to initialize.
bufferBacking storage to consume sequentially.
capacityTotal number of bytes available in buffer.

Definition at line 17 of file session_manager.c.

Referenced by session_manager_init().

◆ session_arena_reset()

void session_arena_reset ( struct session_arena *  arena)

Reset the request arena so future allocations reuse the full buffer.

Parameters
arenaArena to reset.

Reset the request arena so future allocations reuse the full buffer.

Reset a session arena.

Parameters
arenaArena to reset.

Definition at line 46 of file session_manager.c.

Referenced by session_manager_reset().

◆ session_manager_init()

void session_manager_init ( struct session_manager *  manager,
uint8_t *  buffer,
size_t  capacity 
)

Initialize a session manager around a caller-supplied arena buffer.

Parameters
managerSession manager to initialize.
bufferBuffer used for request-scoped arena allocations.
capacitySize of buffer in bytes.

Initialize a session manager around a caller-supplied arena buffer.

Initialize session manager.

Parameters
managerManager to initialize.
bufferBacking arena storage.
capacitySize of buffer in bytes.

Definition at line 116 of file session_manager.c.

◆ session_manager_reset()

void session_manager_reset ( struct session_manager *  manager)

Reset all request-scoped allocations owned by the manager.

Parameters
managerSession manager to reset.

Reset session manager.

Parameters
managerManager whose arena should be rewound.

Definition at line 125 of file session_manager.c.

◆ session_rc_init()

void session_rc_init ( struct session_rc_header *  header,
void(*)(void *)  destructor 
)

Initialize the metadata that tracks a shared session allocation.

Parameters
headerHeader to initialize.
destructorOptional destructor invoked before the payload is freed.

Initialize the metadata that tracks a shared session allocation.

Initialize reference-counted header.

Parameters
headerHeader that precedes the payload.
destructorOptional callback run just before the payload is freed.

Definition at line 56 of file session_manager.c.

Referenced by session_shared_alloc().

◆ session_shared_alloc()

void * session_shared_alloc ( size_t  payload_size,
void(*)(void *)  destructor 
)

Allocate a zeroed payload preceded by a reference-count header.

Parameters
payload_sizeNumber of bytes to expose to the caller.
destructorOptional destructor for the payload.
Returns
Pointer to the payload region, or NULL when allocation fails.

Allocate a zeroed payload preceded by a reference-count header.

Allocate shared session memory.

Parameters
payload_sizeNumber of bytes visible to callers.
destructorOptional callback invoked before memory is released.
Returns
Zeroed payload pointer, or NULL when allocation fails.

Definition at line 68 of file session_manager.c.

◆ session_shared_dec()

void session_shared_dec ( void *  payload)

Decrement the reference count and free the payload when it reaches zero.

Parameters
payloadPayload returned by session_shared_alloc().

Decrement the reference count and free the payload when it reaches zero.

Decrement reference count and free if zero.

Parameters
payloadPayload returned by session_shared_alloc().

Definition at line 96 of file session_manager.c.

◆ session_shared_inc()

void session_shared_inc ( void *  payload)

Increment the reference count for a shared payload.

Parameters
payloadPayload returned by session_shared_alloc().

Increment reference count.

Parameters
payloadPayload returned by session_shared_alloc().

Definition at line 84 of file session_manager.c.