X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Fheap.h;h=ad362a6b1966867a04a16b25854bf3b6bdc195e6;hb=7ce645a0dc4cd3683f854f3aa85a72a86101ddbd;hp=7044f33134cf3a40078ed8173bea9bf4c950be08;hpb=b90e284547eab472e3d9e478a058304bdd6b2da7;p=bertos.git diff --git a/bertos/struct/heap.h b/bertos/struct/heap.h index 7044f331..ad362a6b 100644 --- a/bertos/struct/heap.h +++ b/bertos/struct/heap.h @@ -38,6 +38,9 @@ * * \version $Id$ * \author Bernie Innocenti + * + * $WIZ$ module_name = "heap" + * $WIZ$ module_configuration = "bertos/cfg/cfg_heap.h" */ #ifndef STRUCT_HEAP_H @@ -45,15 +48,33 @@ #include "cfg/cfg_heap.h" #include +#include // IS_POW2() + +/* NOTE: struct size must be a 2's power! */ +typedef struct _MemChunk +{ + struct _MemChunk *next; + size_t size; +} MemChunk; + +STATIC_ASSERT(IS_POW2(sizeof(MemChunk))); -struct _MemChunk; +typedef MemChunk heap_buf_t; /// A heap -struct Heap +typedef struct Heap { struct _MemChunk *FreeList; ///< Head of the free list -}; +} Heap; +/** + * Utility macro to allocate a heap of size \a size. + * + * \param name Variable name for the heap. + * \param size Heap size in bytes. + */ +#define HEAP_DEFINE_BUF(name, size) \ + heap_buf_t name[((size) + sizeof(heap_buf_t) - 1) / sizeof(heap_buf_t)] /// Initialize \a heap within the buffer pointed by \a memory which is of \a size bytes void heap_init(struct Heap* heap, void* memory, size_t size); @@ -86,4 +107,8 @@ void heap_free(struct Heap* heap, void * mem); #endif +int heap_testSetup(void); +int heap_testRun(void); +int heap_testTearDown(void); + #endif /* STRUCT_HEAP_H */