freelist: Move align macro fiddling into header

This commit is contained in:
Imbus 2025-09-08 07:43:15 +02:00
parent 39c331cd09
commit be3d902be5
2 changed files with 13 additions and 13 deletions

View file

@ -5,19 +5,6 @@
#include <stdio.h>
#include <stdlib.h>
/* Fiddle these around according to your need. */
#ifdef FREELIST_NOALIGN
#define ALIGN(x) (x)
#else // FREELIST_NOALIGN
/* Align to nearest multiple of sizeof(void*) */
static inline size_t align_up(size_t n) {
return (n + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
}
#define ALIGN(x) (align_up(x))
#endif // FREELIST_NOALIGN
/* Initialize the FreeList */
int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
size_t size = ALIGN(itemsize + sizeof(FreeListBlock));

View file

@ -5,6 +5,19 @@
#include <stdint.h>
#include <stdlib.h>
/* Fiddle these around according to your need. Delete or check makefile */
#ifdef FREELIST_NOALIGN
#define ALIGN(x) (x)
#else // FREELIST_NOALIGN
/* Align to nearest multiple of sizeof(void*) */
static inline size_t align_up(size_t n) {
return (n + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
}
#define ALIGN(x) (align_up(x))
#endif // FREELIST_NOALIGN
#define FL_FREE ((uint8_t)0x00)
#define FL_USED ((uint8_t)0x01)