29static const char*
const s_tag =
"ra8_slab";
95 const uint32_t count = buffer_bytes / cell_bytes;
99 slab->
base = (uint8_t*)buffer;
102 for (uint32_t i = 0U; i < count; ++i) {
103 const uint32_t next = ((i + 1U) < count) ? (i + 1U) : (uint32_t)
k_ra8_slab_nil;
121 *out_cell = (
void*)&slab->
base[(
size_t)idx * (size_t)slab->
cell_bytes];
129 const uintptr_t cell_addr = (uintptr_t)cell;
130 const uintptr_t base_addr = (uintptr_t)slab->
base;
131 if (cell_addr < base_addr) {
134 const uintptr_t off = cell_addr - base_addr;
139 if ((off % (uintptr_t)slab->
cell_bytes) != 0U) {
142 const uint32_t idx = (uint32_t)(off / (uintptr_t)slab->
cell_bytes);
152 if (slab->
base ==
nullptr) {
155 if (out_free !=
nullptr) {
158 if (out_total !=
nullptr) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
ra8_err_t ra8_slab_alloc(ra8_slab_t *slab, void **out_cell)
Allocate one cell from the slab (O(1)).
static void internal_slab_set_next(ra8_slab_t *slab, uint32_t idx, uint32_t next)
Write the freelist next-index into cell idx.
ra8_err_t ra8_slab_free(ra8_slab_t *slab, void *cell)
Return a previously-allocated cell to the slab (O(1)).
ra8_err_t ra8_slab_init(ra8_slab_t *slab, void *buffer, uint32_t buffer_bytes, uint32_t cell_bytes)
Initialise a slab over a caller-owned buffer.
ra8_err_t ra8_slab_stats(const ra8_slab_t *slab, uint32_t *out_free, uint32_t *out_total)
Report the slab's free / total cell counts.
static uint32_t internal_slab_next(const ra8_slab_t *slab, uint32_t idx)
Read the freelist next-index stored in free cell idx.
Fixed-cell slab allocator – O(1), zero-fragmentation, zero-heap.
@ k_ra8_slab_align_bytes
Required cell-size + buffer alignment.
@ k_ra8_slab_nil
Freelist terminator (no next cell).
@ k_ra8_slab_min_cell_bytes
Smallest cell (holds one index).
Caller-owned state for one fixed-cell pool.
uint32_t cell_bytes
Bytes per cell (>= 4, multiple of 4).
uint32_t free_head
Index of the first free cell, or k_ra8_slab_nil.
uint32_t cell_count
Total cells the buffer was divided into.
uint32_t free_count
Cells currently free (observability).
uint8_t * base
First byte of the cell array (caller buffer).