Compare commits
2 commits
de6aee3a3a
...
d608a81674
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d608a81674 | ||
|
|
f29035319c |
2 changed files with 14 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -O2
|
CFLAGS = -Wall -O2
|
||||||
|
|
||||||
CFLAGS += -DFREELIST_NOALIGN
|
CFLAGS += -DFREELIST_ALIGN
|
||||||
|
|
||||||
TARGET = main.elf
|
TARGET = main.elf
|
||||||
SRC = main.c freelist.c
|
SRC = main.c freelist.c
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,26 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Fiddle these around according to your need. Delete or check makefile */
|
/* Align to nearest multiple of align */
|
||||||
#ifdef FREELIST_NOALIGN
|
static inline size_t align_up_to(size_t n, size_t align) {
|
||||||
#define ALIGN(x) (x)
|
return (n + align - 1) & ~(align - 1);
|
||||||
#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))
|
/* Fiddle these around according to your need. Delete or check makefile */
|
||||||
#endif // FREELIST_NOALIGN
|
#ifdef FREELIST_ALIGN
|
||||||
|
#define ALIGN(x) (align_up_to(x, sizeof(void *)))
|
||||||
|
#else
|
||||||
|
#define ALIGN(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct FreeListBlock FreeListBlock;
|
typedef struct FreeListBlock FreeListBlock;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uintptr_t start;
|
|
||||||
uintptr_t end;
|
|
||||||
FreeListBlock *free;
|
FreeListBlock *free;
|
||||||
size_t size;
|
uintptr_t start;
|
||||||
size_t allocated;
|
uintptr_t end;
|
||||||
|
size_t size;
|
||||||
|
size_t allocated;
|
||||||
} FreeList;
|
} 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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue