heap.h

Go to the documentation of this file.
00001 #ifndef _SYS_HEAP_H_
00002 #define _SYS_HEAP_H_
00003 
00004 /*
00005  * Copyright (C) 2009 by egnite GmbH
00006  * Copyright (C) 2001-2003 by egnite Software GmbH
00007  *
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. Neither the name of the copyright holders nor the names of
00020  *    contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00024  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00027  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00030  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00031  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00033  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGE.
00035  *
00036  * For additional information see http://www.ethernut.de/
00037  */
00038 
00039 /*
00040  * $Id: heap.h 2560 2009-03-18 04:00:06Z thiagocorrea $
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 #ifdef NUTMEM_SPLIT_FAST
00093 
00094 HEAPNODE *heapFastMemFreeList;
00095 
00096 #define NutHeapFastMemAdd(a, s)         NutHeapRootAdd(&heapFastMemFreeList, a, s)
00097 #define NutHeapFastMemAvailable()       NutHeapRootAvailable(&heapFastMemFreeList)
00098 #define NutHeapFastMemRegionAvailable() NutHeapRootRegionAvailable(&heapFastMemFreeList)
00099 
00100 #ifdef NUTDEBUG_HEAP
00101 #define NutHeapFastMemAlloc(s)          NutHeapDebugRootAlloc(&heapFastMemFreeList, s, __FILE__, __LINE__)
00102 #define NutHeapFastMemAllocClear(s)     NutHeapDebugRootAllocClear(&heapFastMemFreeList, s, __FILE__, __LINE__)
00103 #define NutHeapFastMemFree(p)           NutHeapDebugRootFree(&heapFastMemFreeList, p, __FILE__, __LINE__)
00104 #define NutHeapFastMemRealloc(p, s)     NutHeapDebugRootRealloc(&heapFastMemFreeList, p, s, __FILE__, __LINE__)
00105 #else
00106 #define NutHeapFastMemAlloc(s)          NutHeapRootAlloc(&heapFastMemFreeList, s)
00107 #define NutHeapFastMemAllocClear(s)     NutHeapRootAllocClear(&heapFastMemFreeList, s)
00108 #define NutHeapFastMemFree(p)           NutHeapRootFree(&heapFastMemFreeList, p)
00109 #define NutHeapFastMemRealloc(p, s)     NutHeapRootRealloc(&heapFastMemFreeList, p, s)
00110 #endif
00111 
00112 #endif /* NUTMEM_SPLIT_FAST */
00113 
00114 #if defined(NUTMEM_STACKHEAP) && defined(NUTMEM_SPLIT_FAST)
00115 /* Dedicated stack memory. */
00116 #define NutStackAlloc(s)                NutHeapFastMemAlloc(s)
00117 #define NutStackFree(p)                 NutHeapFastMemFree(p)
00118 #else
00119 /* Thread stacks resides in normal heap. */
00120 #define NutStackAlloc(s)                NutHeapAlloc(s)
00121 #define NutStackFree(p)                 NutHeapFree(p)
00122 #endif
00123 
00124 __BEGIN_DECLS
00125 /* Prototypes */
00126 
00127 extern void NutHeapRootAdd(HEAPNODE** root, void *addr, size_t size);
00128 extern size_t NutHeapRootAvailable(HEAPNODE** root);
00129 extern size_t NutHeapRootRegionAvailable(HEAPNODE** root);
00130 
00131 #ifdef NUTDEBUG_HEAP
00132 extern void *NutHeapDebugRootAlloc(HEAPNODE** root, size_t size, CONST char *file, int line);
00133 extern void *NutHeapDebugRootAllocClear(HEAPNODE** root, size_t size, CONST char *file, int line);
00134 extern int NutHeapDebugRootFree(HEAPNODE** root, void *block, CONST char *file, int line);
00135 extern void *NutHeapDebugRootRealloc(HEAPNODE** root, void * block, size_t size, CONST char *file, int line);
00136 #else
00137 extern void *NutHeapRootAlloc(HEAPNODE** root, size_t size);
00138 extern void *NutHeapRootAllocClear(HEAPNODE** root, size_t size);
00139 extern int NutHeapRootFree(HEAPNODE** root, void *block);
00140 extern void *NutHeapRootRealloc(HEAPNODE** root, void * block, size_t size);
00141 #endif
00142 
00143 extern int NutHeapCheck(void);
00144 extern void NutHeapDump(void * stream);
00145 
00146 /* Prototypes */
00147 __BEGIN_DECLS
00148 
00149 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/