Initial implementation of a freelist. blocks contain a header
This commit is contained in:
parent
f01b71f4a6
commit
d583dbaced
3 changed files with 152 additions and 0 deletions
34
kern/libkern/freelist.h
Normal file
34
kern/libkern/freelist.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef FREELIST_H
|
||||
#define FREELIST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define FL_FREE ((uint8_t)0x00)
|
||||
#define FL_USED ((uint8_t)0x01)
|
||||
|
||||
typedef struct FreeListBlock {
|
||||
struct FreeListBlock *next;
|
||||
uint8_t block_state;
|
||||
} FreeListBlock;
|
||||
|
||||
typedef struct {
|
||||
uintptr_t start;
|
||||
uintptr_t end;
|
||||
FreeListBlock *free;
|
||||
size_t size;
|
||||
size_t allocated;
|
||||
} FreeList;
|
||||
|
||||
int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize);
|
||||
int fl_free(FreeList *fl, void *ptr);
|
||||
int fl_is_managed(FreeList *fl, void *ptr);
|
||||
void *fl_alloc(FreeList *fl);
|
||||
size_t fl_check(FreeList *fl);
|
||||
size_t fl_allocated(FreeList *fl);
|
||||
size_t fl_available(FreeList *fl);
|
||||
size_t fl_capacity(FreeList *fl);
|
||||
float fl_utilization(FreeList *fl, size_t itemsize);
|
||||
|
||||
#endif // FREELIST_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue