spool: Clean up with gcc/clang specific features

This commit is contained in:
Nils O. Selåsdal
2026-04-07 20:59:33 +02:00
parent 4e28b2255c
commit a4547f6736
3 changed files with 40 additions and 27 deletions
+10 -4
View File
@@ -1,5 +1,5 @@
#ifndef UC_SPOOL_H_
#define UC_SPOOL_H
#define UC_SPOOL_H_
#include <stddef.h>
#include <stdint.h>
@@ -7,6 +7,11 @@
extern "C" {
#endif
typedef union UCPoolBlock UCPoolBlock;
union UCPoolBlock {
UCPoolBlock *next; // next free block (when not allocated)
unsigned char data[]; // data when allocated
};
/** @file
* Static pool allocator.
*
@@ -23,12 +28,12 @@ extern "C" {
*/
typedef struct UCPool UCPool;
struct UCPool {
unsigned char *free_list; // intrusive free list
UCPoolBlock *free_list; // free list
size_t block_size; // aligned size of each block
size_t capacity; // number of blocks
size_t align; // alignment
unsigned char *start; // start of user buffer
unsigned char *end; // one past end of user buffer
UCPoolBlock *start; // start of user buffer
UCPoolBlock *end; // one past end of user buffer
};
/** Initialize the pool.
@@ -47,6 +52,7 @@ void uc_pool_init(UCPool *pool,
size_t alignment);
// Allocate a block from the pool. Returns NULL if no more space
[[gnu::assume_aligned(_Alignof(UCPoolBlock))]]
void *uc_pool_alloc(UCPool *pool);
// Free @p . Returns memory to the pool