1 #ifndef CYGONCE_MEMALLOC_KAPI_H
2 #define CYGONCE_MEMALLOC_KAPI_H
4 /*==========================================================================
8 // Memory allocator portion of kernel C API
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
46 // Author(s): jlarmour
49 // Purpose: Memory allocator portion of kernel C API
50 // Description: This is intentionally only to be included from
51 // <cyg/kernel/kapi.h>
52 // Usage: This file should not be used directly - instead it should
53 // be used via <cyg/kernel/kapi.h>
56 //####DESCRIPTIONEND####
58 //========================================================================*/
61 #include <pkgconf/system.h>
62 #include <pkgconf/memalloc.h>
64 /* TYPE DEFINITIONS */
66 #include <cyg/kernel/kapi.h>
68 typedef cyg_uint32 cyg_handle_t;
71 /*---------------------------------------------------------------------------*/
77 /*---------------------------------------------------------------------------*/
78 struct cyg_mempool_var;
79 typedef struct cyg_mempool_var cyg_mempool_var;
81 struct cyg_mempool_fix;
82 typedef struct cyg_mempool_fix cyg_mempool_fix;
84 /*-----------------------------------------------------------------------*/
87 /* There are two sorts of memory pools. A variable size memory pool
88 is for allocating blocks of any size. A fixed size memory pool, has
89 the block size specified when the pool is created, and only provides
90 blocks of that size. */
92 /* Create a variable size memory pool */
93 void cyg_mempool_var_create(
94 void *base, /* base of memory to use for pool */
95 cyg_int32 size, /* size of memory in bytes */
96 cyg_handle_t *handle, /* returned handle of memory pool */
97 cyg_mempool_var *var /* space to put pool structure in */
100 /* Delete variable size memory pool */
101 void cyg_mempool_var_delete(cyg_handle_t varpool) __THROW;
103 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
105 /* Allocates a block of length size. This waits if the memory is not
106 currently available. */
107 void *cyg_mempool_var_alloc(cyg_handle_t varpool, cyg_int32 size) __THROW;
109 # ifdef CYGFUN_KERNEL_THREADS_TIMER
111 /* Allocates a block of length size. This waits until abstime,
112 if the memory is not already available. NULL is returned if
113 no memory is available. */
114 void *cyg_mempool_var_timed_alloc(
115 cyg_handle_t varpool,
117 cyg_tick_count_t abstime) __THROW;
122 /* Allocates a block of length size. NULL is returned if no memory is
124 void *cyg_mempool_var_try_alloc(
125 cyg_handle_t varpool,
126 cyg_int32 size) __THROW;
128 /* Frees memory back into variable size pool. */
129 void cyg_mempool_var_free(cyg_handle_t varpool, void *p) __THROW;
131 /* Returns true if there are any threads waiting for memory in the
132 given memory pool. */
133 cyg_bool_t cyg_mempool_var_waiting(cyg_handle_t varpool) __THROW;
141 cyg_int32 maxfree; // The largest free block
144 /* Puts information about a variable memory pool into the structure
146 void cyg_mempool_var_get_info(cyg_handle_t varpool, cyg_mempool_info *info) __THROW;
148 /* Create a fixed size memory pool */
149 void cyg_mempool_fix_create(
150 void *base, // base of memory to use for pool
151 cyg_int32 size, // size of memory in byte
152 cyg_int32 blocksize, // size of allocation in bytes
153 cyg_handle_t *handle, // handle of memory pool
154 cyg_mempool_fix *fix // space to put pool structure in
157 /* Delete fixed size memory pool */
158 void cyg_mempool_fix_delete(cyg_handle_t fixpool) __THROW;
160 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE
161 /* Allocates a block. This waits if the memory is not
162 currently available. */
163 void *cyg_mempool_fix_alloc(cyg_handle_t fixpool) __THROW;
165 # ifdef CYGFUN_KERNEL_THREADS_TIMER
167 /* Allocates a block. This waits until abstime, if the memory
168 is not already available. NULL is returned if no memory is
170 void *cyg_mempool_fix_timed_alloc(
171 cyg_handle_t fixpool,
172 cyg_tick_count_t abstime) __THROW;
177 /* Allocates a block. NULL is returned if no memory is available. */
178 void *cyg_mempool_fix_try_alloc(cyg_handle_t fixpool) __THROW;
180 /* Frees memory back into fixed size pool. */
181 void cyg_mempool_fix_free(cyg_handle_t fixpool, void *p) __THROW;
183 /* Returns true if there are any threads waiting for memory in the
184 given memory pool. */
185 cyg_bool_t cyg_mempool_fix_waiting(cyg_handle_t fixpool) __THROW;
187 /* Puts information about a variable memory pool into the structure
189 void cyg_mempool_fix_get_info(cyg_handle_t fixpool, cyg_mempool_info *info) __THROW;
191 /* user overrideable function invoked before running out of memory. */
192 __externC void cyg_memalloc_alloc_fail(char * file, int line, cyg_int32 size)
195 /*---------------------------------------------------------------------------*/
200 /*---------------------------------------------------------------------------*/
203 #endif /* ifndef CYGONCE_MEMALLOC_KAPI_H */