X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Fheap.h;h=d76678b2090757a4a2c05e05a2394121644254bf;hb=32d1445272120a254d77ce8d1af1f527da7a2c17;hp=c19c2ec76653cf118683bda9bbb2a08e4b73a356;hpb=23b7f48a17d33a426782161f721cff4fc6611ddf;p=bertos.git diff --git a/bertos/struct/heap.h b/bertos/struct/heap.h index c19c2ec7..d76678b2 100644 --- a/bertos/struct/heap.h +++ b/bertos/struct/heap.h @@ -36,7 +36,7 @@ * in this form also within the implementation. This would probably remove * memory alignment problems, and also some aliasing issues. * - * \version $Id: heap.h 1532 2008-08-04 07:21:26Z bernie $ + * \version $Id$ * \author Bernie Innocenti */ @@ -45,15 +45,34 @@ #include "cfg/cfg_heap.h" #include +#include // IS_POW2() -struct _MemChunk; +/* 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))); + +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)]; \ + STATIC_ASSERT(sizeof(name) % sizeof(heap_buf_t) == 0) /// 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 +105,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 */