|
cwist
Modern C web framework with libttak runtime
|
Session allocation helpers built from a resettable arena and RC payloads. More...
#include <cwist/sys/session/session_manager.h>#include <cwist/core/mem/alloc.h>#include <stdlib.h>#include <string.h>
Go to the source code of this file.
Functions | |
| void | session_arena_init (struct session_arena *arena, uint8_t *buffer, size_t capacity) |
| Initialize a linear arena over caller-provided storage. | |
| void * | session_arena_alloc (struct session_arena *arena, size_t size) |
| Allocate aligned bytes from the request arena. | |
| void | session_arena_reset (struct session_arena *arena) |
| Rewind the arena so subsequent allocations reuse the full buffer. | |
| void | session_rc_init (struct session_rc_header *header, void(*destructor)(void *)) |
| Initialize the reference-count metadata for a shared payload. | |
| void * | session_shared_alloc (size_t payload_size, void(*destructor)(void *)) |
| Allocate a shared payload with an in-band reference-count header. | |
| void | session_shared_inc (void *payload) |
| Increment the reference count for a shared payload. | |
| void | session_shared_dec (void *payload) |
| Drop a reference and destroy the payload when the count reaches zero. | |
| void | session_manager_init (struct session_manager *manager, uint8_t *buffer, size_t capacity) |
| Initialize the request-scoped allocator state for a session manager. | |
| void | session_manager_reset (struct session_manager *manager) |
| Reset all request-scoped allocations owned by the manager. | |
Session allocation helpers built from a resettable arena and RC payloads.
Definition in file session_manager.c.
| void * session_arena_alloc | ( | struct session_arena * | arena, |
| size_t | size | ||
| ) |
Allocate aligned bytes from the request arena.
Allocate aligned storage from the request arena.
Allocate from a session arena.
| arena | Arena that owns the backing storage. |
| size | Number of bytes requested before alignment. |
Definition at line 30 of file session_manager.c.
References session_arena::buffer, cap, session_arena::capacity, and session_arena::offset.
| void session_arena_init | ( | struct session_arena * | arena, |
| uint8_t * | buffer, | ||
| size_t | capacity | ||
| ) |
Initialize a linear arena over caller-provided storage.
Bind a caller-owned buffer to a session arena and reset its cursor.
Initialize a session arena.
| arena | Arena to initialize. |
| buffer | Backing storage to consume sequentially. |
| capacity | Total number of bytes available in buffer. |
Definition at line 17 of file session_manager.c.
References session_arena::buffer, session_arena::capacity, and session_arena::offset.
Referenced by session_manager_init().
| void session_arena_reset | ( | struct session_arena * | arena | ) |
Rewind the arena so subsequent allocations reuse the full buffer.
Reset the request arena so future allocations reuse the full buffer.
Reset a session arena.
| arena | Arena to reset. |
Definition at line 46 of file session_manager.c.
References session_arena::offset.
Referenced by session_manager_reset().
| void session_manager_init | ( | struct session_manager * | manager, |
| uint8_t * | buffer, | ||
| size_t | capacity | ||
| ) |
Initialize the request-scoped allocator state for a session manager.
Initialize a session manager around a caller-supplied arena buffer.
Initialize session manager.
| manager | Manager to initialize. |
| buffer | Backing arena storage. |
| capacity | Size of buffer in bytes. |
Definition at line 116 of file session_manager.c.
References cap, and session_arena_init().
| void session_manager_reset | ( | struct session_manager * | manager | ) |
Reset all request-scoped allocations owned by the manager.
Reset session manager.
| manager | Manager whose arena should be rewound. |
Definition at line 125 of file session_manager.c.
References cap, and session_arena_reset().
| void session_rc_init | ( | struct session_rc_header * | header, |
| void(*)(void *) | destructor | ||
| ) |
Initialize the reference-count metadata for a shared payload.
Initialize the metadata that tracks a shared session allocation.
Initialize reference-counted header.
| header | Header that precedes the payload. |
| destructor | Optional callback run just before the payload is freed. |
Definition at line 56 of file session_manager.c.
References session_rc_header::destructor, and session_rc_header::ref_count.
Referenced by session_shared_alloc().
Allocate a shared payload with an in-band reference-count header.
Allocate a zeroed payload preceded by a reference-count header.
Allocate shared session memory.
| payload_size | Number of bytes visible to callers. |
| destructor | Optional callback invoked before memory is released. |
Definition at line 68 of file session_manager.c.
References cap, cwist_alloc(), session_rc_header::destructor, and session_rc_init().
Drop a reference and destroy the payload when the count reaches zero.
Decrement the reference count and free the payload when it reaches zero.
Decrement reference count and free if zero.
| payload | Payload returned by session_shared_alloc(). |
Definition at line 96 of file session_manager.c.
References cap, cwist_free(), session_rc_header::destructor, and session_rc_header::ref_count.
Increment the reference count for a shared payload.
Increment reference count.
| payload | Payload returned by session_shared_alloc(). |
Definition at line 84 of file session_manager.c.
References cap, and session_rc_header::ref_count.