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 2727 2009-09-29 18:19:05Z haraldkipp $
00041  */
00042 
00043 #include <cfg/memory.h>
00044 #include <sys/types.h>
00045 
00055 typedef struct _HEAPNODE HEAPNODE;
00056 
00061 struct _HEAPNODE {
00062     size_t hn_size;     
00063 #ifdef NUTDEBUG_HEAP
00064     HEAPNODE *ht_next;
00065     size_t ht_size;
00066     CONST char *ht_file;
00067     int ht_line;
00068 #endif
00069     HEAPNODE *hn_next;  
00070 };
00071 
00072 
00073 extern HEAPNODE *heapFreeList;
00074 
00075 #define NutHeapAdd(a, s)                NutHeapRootAdd(&heapFreeList, a, s)
00076 #define NutHeapAvailable()              NutHeapRootAvailable(&heapFreeList)
00077 #define NutHeapRegionAvailable()        NutHeapRootRegionAvailable(&heapFreeList)
00078 
00079 #ifdef NUTDEBUG_HEAP
00080 #define NutHeapAlloc(s)                 NutHeapDebugRootAlloc(&heapFreeList, s, __FILE__, __LINE__)
00081 #define NutHeapAllocClear(s)            NutHeapDebugRootAllocClear(&heapFreeList, s, __FILE__, __LINE__)
00082 #define NutHeapFree(p)                  NutHeapDebugRootFree(&heapFreeList, p, __FILE__, __LINE__)
00083 #define NutHeapRealloc(p, s)            NutHeapDebugRootRealloc(&heapFreeList, p, s, __FILE__, __LINE__)
00084 #else
00085 #define NutHeapAlloc(s)                 NutHeapRootAlloc(&heapFreeList, s)
00086 #define NutHeapAllocClear(s)            NutHeapRootAllocClear(&heapFreeList, s)
00087 #define NutHeapFree(p)                  NutHeapRootFree(&heapFreeList, p)
00088 #define NutHeapRealloc(p, s)            NutHeapRootRealloc(&heapFreeList, p, s)
00089 #endif
00090 
00091 #if defined(NUTMEM_STACKHEAP)
00092 /* Dedicated stack memory. */
00093 #ifndef NUTMEM_SPLIT_FAST
00094 #define NUTMEM_SPLIT_FAST
00095 #endif
00096 #define NutStackAdd(a, s)               NutHeapFastMemAdd(a, s)
00097 #define NutStackAlloc(s)                NutHeapFastMemAlloc(s)
00098 #define NutStackFree(p)                 NutHeapFastMemFree(p)
00099 #else /* NUTMEM_STACKHEAP */
00100 /* Thread stacks resides in normal heap. */
00101 #define NutStackAlloc(s)                NutHeapAlloc(s)
00102 #define NutStackFree(p)                 NutHeapFree(p)
00103 #endif /* NUTMEM_STACKHEAP */
00104 
00105 #ifdef NUTMEM_SPLIT_FAST
00106 
00107 extern HEAPNODE *heapFastMemFreeList;
00108 
00109 #define NutHeapFastMemAdd(a, s)         NutHeapRootAdd(&heapFastMemFreeList, a, s)
00110 #define NutHeapFastMemAvailable()       NutHeapRootAvailable(&heapFastMemFreeList)
00111 #define NutHeapFastMemRegionAvailable() NutHeapRootRegionAvailable(&heapFastMemFreeList)
00112 
00113 #ifdef NUTDEBUG_HEAP
00114 #define NutHeapFastMemAlloc(s)          NutHeapDebugRootAlloc(&heapFastMemFreeList, s, __FILE__, __LINE__)
00115 #define NutHeapFastMemAllocClear(s)     NutHeapDebugRootAllocClear(&heapFastMemFreeList, s, __FILE__, __LINE__)
00116 #define NutHeapFastMemFree(p)           NutHeapDebugRootFree(&heapFastMemFreeList, p, __FILE__, __LINE__)
00117 #define NutHeapFastMemRealloc(p, s)     NutHeapDebugRootRealloc(&heapFastMemFreeList, p, s, __FILE__, __LINE__)
00118 #else
00119 #define NutHeapFastMemAlloc(s)          NutHeapRootAlloc(&heapFastMemFreeList, s)
00120 #define NutHeapFastMemAllocClear(s)     NutHeapRootAllocClear(&heapFastMemFreeList, s)
00121 #define NutHeapFastMemFree(p)           NutHeapRootFree(&heapFastMemFreeList, p)
00122 #define NutHeapFastMemRealloc(p, s)     NutHeapRootRealloc(&heapFastMemFreeList, p, s)
00123 #endif
00124 
00125 #endif /* NUTMEM_SPLIT_FAST */
00126 
00127 __BEGIN_DECLS
00128 /* Prototypes */
00129 
00130 extern void NutHeapRootAdd(HEAPNODE** root, void *addr, size_t size);
00131 extern size_t NutHeapRootAvailable(HEAPNODE** root);
00132 extern size_t NutHeapRootRegionAvailable(HEAPNODE** root);
00133 
00134 #ifdef NUTDEBUG_HEAP
00135 extern void *NutHeapDebugRootAlloc(HEAPNODE** root, size_t size, CONST char *file, int line);
00136 extern void *NutHeapDebugRootAllocClear(HEAPNODE** root, size_t size, CONST char *file, int line);
00137 extern int NutHeapDebugRootFree(HEAPNODE** root, void *block, CONST char *file, int line);
00138 extern void *NutHeapDebugRootRealloc(HEAPNODE** root, void * block, size_t size, CONST char *file, int line);
00139 #else
00140 extern void *NutHeapRootAlloc(HEAPNODE** root, size_t size);
00141 extern void *NutHeapRootAllocClear(HEAPNODE** root, size_t size);
00142 extern int NutHeapRootFree(HEAPNODE** root, void *block);
00143 extern void *NutHeapRootRealloc(HEAPNODE** root, void * block, size_t size);
00144 #endif
00145 
00146 extern int NutHeapCheck(void);
00147 extern void NutHeapDump(void * stream);
00148 
00149 /* Prototypes */
00150 __END_DECLS
00151 
00152 #endif

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