00001 #ifndef _SYS_HEAP_H_
00002 #define _SYS_HEAP_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <cfg/memory.h>
00044 #include <sys/types.h>
00045
00046
00056 typedef struct _HEAPNODE HEAPNODE;
00057
00062 struct _HEAPNODE {
00063 size_t hn_size;
00064 #ifdef NUTDEBUG_HEAP
00065 HEAPNODE *ht_next;
00066 size_t ht_size;
00067 CONST char *ht_file;
00068 int ht_line;
00069 #endif
00070 HEAPNODE *hn_next;
00071 };
00072
00073
00074 extern HEAPNODE *heapFreeList;
00075
00076 #define NutHeapAdd(a, s) NutHeapRootAdd(&heapFreeList, a, s)
00077 #define NutHeapAvailable() NutHeapRootAvailable(&heapFreeList)
00078 #define NutHeapRegionAvailable() NutHeapRootRegionAvailable(&heapFreeList)
00079
00080 #ifdef NUTDEBUG_HEAP
00081 #define NutHeapAlloc(s) NutHeapDebugRootAlloc(&heapFreeList, s, __FILE__, __LINE__)
00082 #define NutHeapAllocClear(s) NutHeapDebugRootAllocClear(&heapFreeList, s, __FILE__, __LINE__)
00083 #define NutHeapFree(p) NutHeapDebugRootFree(&heapFreeList, p, __FILE__, __LINE__)
00084 #define NutHeapRealloc(p, s) NutHeapDebugRootRealloc(&heapFreeList, p, s, __FILE__, __LINE__)
00085 #else
00086 #define NutHeapAlloc(s) NutHeapRootAlloc(&heapFreeList, s)
00087 #define NutHeapAllocClear(s) NutHeapRootAllocClear(&heapFreeList, s)
00088 #define NutHeapFree(p) NutHeapRootFree(&heapFreeList, p)
00089 #define NutHeapRealloc(p, s) NutHeapRootRealloc(&heapFreeList, p, s)
00090 #endif
00091
00092 #if defined(NUTMEM_STACKHEAP)
00093
00094 #ifndef NUTMEM_SPLIT_FAST
00095 #define NUTMEM_SPLIT_FAST
00096 #endif
00097 #define NutStackAdd(a, s) NutHeapFastMemAdd(a, s)
00098 #define NutStackAlloc(s) NutHeapFastMemAlloc(s)
00099 #define NutStackFree(p) NutHeapFastMemFree(p)
00100 #else
00101
00102 #define NutStackAlloc(s) NutHeapAlloc(s)
00103 #define NutStackFree(p) NutHeapFree(p)
00104 #endif
00105
00106 #ifdef NUTMEM_SPLIT_FAST
00107
00108 extern HEAPNODE *heapFastMemFreeList;
00109
00110 #define NutHeapFastMemAdd(a, s) NutHeapRootAdd(&heapFastMemFreeList, a, s)
00111 #define NutHeapFastMemAvailable() NutHeapRootAvailable(&heapFastMemFreeList)
00112 #define NutHeapFastMemRegionAvailable() NutHeapRootRegionAvailable(&heapFastMemFreeList)
00113
00114 #ifdef NUTDEBUG_HEAP
00115 #define NutHeapFastMemAlloc(s) NutHeapDebugRootAlloc(&heapFastMemFreeList, s, __FILE__, __LINE__)
00116 #define NutHeapFastMemAllocClear(s) NutHeapDebugRootAllocClear(&heapFastMemFreeList, s, __FILE__, __LINE__)
00117 #define NutHeapFastMemFree(p) NutHeapDebugRootFree(&heapFastMemFreeList, p, __FILE__, __LINE__)
00118 #define NutHeapFastMemRealloc(p, s) NutHeapDebugRootRealloc(&heapFastMemFreeList, p, s, __FILE__, __LINE__)
00119 #else
00120 #define NutHeapFastMemAlloc(s) NutHeapRootAlloc(&heapFastMemFreeList, s)
00121 #define NutHeapFastMemAllocClear(s) NutHeapRootAllocClear(&heapFastMemFreeList, s)
00122 #define NutHeapFastMemFree(p) NutHeapRootFree(&heapFastMemFreeList, p)
00123 #define NutHeapFastMemRealloc(p, s) NutHeapRootRealloc(&heapFastMemFreeList, p, s)
00124 #endif
00125
00126 #endif
00127
00128 __BEGIN_DECLS
00129
00130
00131 extern void NutHeapRootAdd(HEAPNODE** root, void *addr, size_t size);
00132 extern size_t NutHeapRootAvailable(HEAPNODE** root);
00133 extern size_t NutHeapRootRegionAvailable(HEAPNODE** root);
00134
00135 #ifdef NUTDEBUG_HEAP
00136 extern void *NutHeapDebugRootAlloc(HEAPNODE** root, size_t size, CONST char *file, int line);
00137 extern void *NutHeapDebugRootAllocClear(HEAPNODE** root, size_t size, CONST char *file, int line);
00138 extern int NutHeapDebugRootFree(HEAPNODE** root, void *block, CONST char *file, int line);
00139 extern void *NutHeapDebugRootRealloc(HEAPNODE** root, void * block, size_t size, CONST char *file, int line);
00140 #else
00141 extern void *NutHeapRootAlloc(HEAPNODE** root, size_t size);
00142 extern void *NutHeapRootAllocClear(HEAPNODE** root, size_t size);
00143 extern int NutHeapRootFree(HEAPNODE** root, void *block);
00144 extern void *NutHeapRootRealloc(HEAPNODE** root, void * block, size_t size);
00145 #endif
00146
00147 extern int NutHeapCheck(void);
00148 extern void NutHeapDump(void * stream);
00149
00150
00151 __END_DECLS
00152
00153 #endif