heap.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef _SYS_HEAP_H_
  2. #define _SYS_HEAP_H_
  3. /*
  4. * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  36. *
  37. * This file is distributed in the hope that it will be useful, but WITHOUT
  38. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  39. * FITNESS FOR A PARTICULAR PURPOSE.
  40. *
  41. * You can redistribute this file and/or modify it under the terms of the GNU
  42. * General Public License (GPL) as published by the Free Software Foundation;
  43. * either version 2 of the License, or (at your discretion) any later version.
  44. * See the accompanying file "copying-gpl.txt" for more details.
  45. *
  46. * As a special exception to the GPL, permission is granted for additional
  47. * uses of the text contained in this file. See the accompanying file
  48. * "copying-liquorice.txt" for details.
  49. */
  50. /*
  51. * $Log: heap.h,v $
  52. * Revision 1.4 2006/10/06 23:19:08 hwmaier
  53. * Added include statement for cfg/memory.h so the macro NUTMEM_STACKHEAP is found when compiling for the AT90CAN128.
  54. *
  55. * Revision 1.3 2006/09/29 12:26:14 haraldkipp
  56. * All code should use dedicated stack allocation routines. For targets
  57. * allocating stack from the normal heap the API calls are remapped by
  58. * preprocessor macros.
  59. * Stack allocation code moved from thread module to heap module.
  60. * Adding static attribute to variable 'available' will avoid interference
  61. * with application code. The ugly format macros had been replaced by
  62. * converting all platform specific sizes to unsigned integers.
  63. *
  64. * Revision 1.2 2004/03/16 16:48:44 haraldkipp
  65. * Added Jan Dubiec's H8/300 port.
  66. *
  67. * Revision 1.1.1.1 2003/05/09 14:41:20 haraldkipp
  68. * Initial using 3.2.1
  69. *
  70. * Revision 1.7 2003/02/04 18:00:52 harald
  71. * Version 3 released
  72. *
  73. * Revision 1.6 2002/06/26 17:29:28 harald
  74. * First pre-release with 2.4 stack
  75. *
  76. */
  77. #include <cfg/memory.h>
  78. #include <sys/types.h>
  79. /*!
  80. * \file sys/heap.h
  81. * \brief Heap management definitions.
  82. */
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86. /*!
  87. * \struct _HEAPNODE heap.h sys/heap.h
  88. * \brief Heap memory node information structure.
  89. */
  90. /*!
  91. * \typedef HEAPNODE
  92. * \brief Heap memory node type.
  93. */
  94. typedef struct _HEAPNODE {
  95. size_t hn_size; /*!< \brief Size of this node. */
  96. struct _HEAPNODE *hn_next; /*!< \brief Link to next free node. */
  97. } HEAPNODE;
  98. extern HEAPNODE* volatile heapFreeList;
  99. /*!
  100. * \brief Allocation threshold.
  101. *
  102. * Might be increased to avoid creating
  103. * too many small nodes.
  104. */
  105. #define ALLOC_THRESHOLD 6
  106. extern void *NutHeapAlloc(size_t size);
  107. extern void *NutHeapAllocClear(size_t size);
  108. extern int NutHeapFree(void *block);
  109. extern void NutHeapAdd(void *addr, size_t size);
  110. extern size_t NutHeapAvailable(void);
  111. #if defined (NUTMEM_STACKHEAP)
  112. /* Dedicated stack memory. */
  113. extern void *NutStackAlloc(size_t size);
  114. extern int NutStackFree(void *block);
  115. extern void NutStackAdd(void *addr, size_t size);
  116. #else /* !NUTMEM_STACKHEAP */
  117. /* Thread stacks resides in normal heap. */
  118. #define NutStackAlloc(size) NutHeapAlloc(size)
  119. #define NutStackFree(block) NutHeapFree(block)
  120. #endif /* !NUTMEM_STACKHEAP */
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif