freelist: Move align macro fiddling into header
This commit is contained in:
parent
39c331cd09
commit
be3d902be5
2 changed files with 13 additions and 13 deletions
|
|
@ -5,19 +5,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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 */
|
/* Initialize the FreeList */
|
||||||
int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
|
int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
|
||||||
size_t size = ALIGN(itemsize + sizeof(FreeListBlock));
|
size_t size = ALIGN(itemsize + sizeof(FreeListBlock));
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,19 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.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_FREE ((uint8_t)0x00)
|
||||||
#define FL_USED ((uint8_t)0x01)
|
#define FL_USED ((uint8_t)0x01)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue