44static inline void internal_pool_push_free_node(
struct pool *self,
struct pool_free_node *node)
62 for (
size_t i = 0; i < chunk_count; i++) {
67 internal_pool_push_free_node(self, node);
80static inline void pool_init(
struct pool *self,
const size_t len,
unsigned char *backing_buf,
const size_t data_size,
81 const size_t data_alignment)
88 size_t chunk_size = data_size >=
sizeof(
struct pool_free_node) ? data_size : sizeof(struct pool_free_node);
92 assert(padding + chunk_size <= len);
94 self->buf_ptr = &backing_buf[padding];
95 self->buf_len = len - padding;
96 self->chunk_size = chunk_size;
97 self->head_ptr = NULL;
134 assert(&self->
buf_ptr[0] <= (
unsigned char *)ptr && (
unsigned char *)ptr < &self->buf_ptr[self->
buf_len]);
138 internal_pool_push_free_node(self, node);
static uintptr_t calc_alignment_padding(const size_t alignment, const uintptr_t ptr)
Calculate the alignment padding required to align a pointer.
Definition align.h:91
static void pool_init(struct pool *self, const size_t len, unsigned char *backing_buf, const size_t data_size, const size_t data_alignment)
Initialize pool for given data size and alignment.
Definition pool.h:80
static void pool_deallocate(struct pool *self, void *ptr)
Free a memory chunk for further reuse.
Definition pool.h:130
static void * pool_allocate(struct pool *self)
Get a pointer to a free block of previously given data size.
Definition pool.h:109
static void pool_deallocate_all(struct pool *self)
Deallocate pool and restore all free nodes.
Definition pool.h:56
Pool node struct.
Definition pool.h:29
struct pool_free_node * next_ptr
pointer to next node
Definition pool.h:30
Pool struct.
Definition pool.h:36
size_t chunk_size
Chunk size.
Definition pool.h:38
struct pool_free_node * head_ptr
Pointer to head node.
Definition pool.h:40
unsigned char * buf_ptr
Underlying buffer.
Definition pool.h:39
size_t buf_len
Underlying buffer length.
Definition pool.h:37