|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Per-worker per-dispatch scratch arenas - implementation. More...
#include "scratch.h"#include "network_drivers/session/worker.h"#include <assert.h>#include <stdint.h>#include "freertos/FreeRTOS.h"#include "freertos/task.h"Go to the source code of this file.
Functions | |
| void * | scratch_alloc (size_t n, size_t align) |
Borrow n bytes of scratch, aligned to align. | |
| void | scratch_reset (void) |
| Reclaim the whole arena (empties it). | |
| size_t | scratch_mark (void) |
| Capture the current arena offset (a savepoint for scratch_release()). | |
| void | scratch_release (size_t mark) |
Reclaim everything allocated since mark (LIFO). | |
| size_t | scratch_used (void) |
| Bytes currently handed out (0 immediately after a reset). | |
| size_t | scratch_high_water (void) |
| Largest scratch_used() value seen since boot (for sizing the arena). | |
| size_t | scratch_capacity (void) |
| Total arena capacity in bytes (DETWS_SCRATCH_ARENA_SIZE). | |
Per-worker per-dispatch scratch arenas - implementation.
One bump allocator per worker (DETWS_WORKER_COUNT arenas in BSS), selected by the caller's worker id. Each arena has exactly one accessor (its worker), so the lock-free / fixed-size guarantees in scratch.h hold per worker. With DETWS_WORKER_COUNT == 1 this is byte-for-byte the original single arena.
Definition in file scratch.cpp.
| void * scratch_alloc | ( | size_t | n, |
| size_t | align | ||
| ) |
Borrow n bytes of scratch, aligned to align.
The returned pointer is valid only until the next scratch_reset() (i.e. only within the current session dispatch). Returns nullptr if the request does not fit the remaining arena - callers MUST handle null and fail closed.
| n | bytes requested (0 yields a valid non-null pointer when space remains). |
| align | required alignment in bytes, a power of two (0 selects the platform default). |
n writable bytes, or nullptr if it does not fit. Definition at line 85 of file scratch.cpp.
References DETWS_SCRATCH_ARENA_SIZE.
Referenced by ssh_conn_close_channel(), ssh_conn_open_forwarded(), ssh_conn_send(), ssh_pkt_recv(), ssh_pkt_send(), and ws_send_frame().
| void scratch_reset | ( | void | ) |
Reclaim the whole arena (empties it).
Called by server_tick() before each event dispatch. Invalidates every pointer previously returned by scratch_alloc().
Definition at line 110 of file scratch.cpp.
| size_t scratch_mark | ( | void | ) |
Capture the current arena offset (a savepoint for scratch_release()).
Definition at line 117 of file scratch.cpp.
| void scratch_release | ( | size_t | mark | ) |
Reclaim everything allocated since mark (LIFO).
Restores the arena to a previous scratch_mark(), freeing every scratch_alloc() made in between. Marks must be released in reverse order (nested scopes). Use ScratchScope for return-safe scoping.
| mark | a value previously returned by scratch_mark() (must be <= the current offset). |
Definition at line 124 of file scratch.cpp.
Referenced by ScratchScope::~ScratchScope().
| size_t scratch_used | ( | void | ) |
Bytes currently handed out (0 immediately after a reset).
Definition at line 132 of file scratch.cpp.
| size_t scratch_high_water | ( | void | ) |
Largest scratch_used() value seen since boot (for sizing the arena).
Definition at line 137 of file scratch.cpp.
References DETWS_WORKER_COUNT.
| size_t scratch_capacity | ( | void | ) |
Total arena capacity in bytes (DETWS_SCRATCH_ARENA_SIZE).
Definition at line 147 of file scratch.cpp.
References DETWS_SCRATCH_ARENA_SIZE.