]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/memalloc/common/v2_0/include/kapi.h
Initial revision
[karo-tx-redboot.git] / packages / services / memalloc / common / v2_0 / include / kapi.h
1 #ifndef CYGONCE_MEMALLOC_KAPI_H
2 #define CYGONCE_MEMALLOC_KAPI_H
3
4 /*==========================================================================
5 //
6 //      kapi.h
7 //
8 //      Memory allocator portion of kernel C API
9 //
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.
15 //
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.
19 //
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
23 // for more details.
24 //
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.
28 //
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.
35 //
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.
38 //
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####
45 //
46 // Author(s):    jlarmour
47 // Contributors: 
48 // Date:         2000-06-12
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>
54 //              
55 //
56 //####DESCRIPTIONEND####
57 //
58 //========================================================================*/
59
60 /* CONFIGURATION */
61 #include <pkgconf/system.h>
62 #include <pkgconf/memalloc.h>
63
64 /* TYPE DEFINITIONS */
65 #ifdef CYGPKG_KERNEL
66 #include <cyg/kernel/kapi.h>
67 #else
68 typedef cyg_uint32 cyg_handle_t;
69 #endif
70
71 /*---------------------------------------------------------------------------*/
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 /*---------------------------------------------------------------------------*/
78 struct cyg_mempool_var;
79 typedef struct cyg_mempool_var cyg_mempool_var;
80
81 struct cyg_mempool_fix;
82 typedef struct cyg_mempool_fix cyg_mempool_fix;
83
84 /*-----------------------------------------------------------------------*/
85 /* Memory pools                                                          */
86
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.  */
91
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 */
98     ) __THROW;
99
100 /* Delete variable size memory pool */
101 void cyg_mempool_var_delete(cyg_handle_t varpool) __THROW;
102
103 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
104
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;
108
109 # ifdef CYGFUN_KERNEL_THREADS_TIMER
110
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,
116     cyg_int32        size,
117     cyg_tick_count_t abstime) __THROW;
118
119 # endif
120 #endif
121
122 /* Allocates a block of length size.  NULL is returned if no memory is
123    available. */
124 void *cyg_mempool_var_try_alloc(
125     cyg_handle_t varpool,
126     cyg_int32    size) __THROW;
127
128 /* Frees memory back into variable size pool. */
129 void cyg_mempool_var_free(cyg_handle_t varpool, void *p) __THROW;
130
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;
134
135 typedef struct {
136     cyg_int32 totalmem;
137     cyg_int32 freemem;
138     void      *base;
139     cyg_int32 size;
140     cyg_int32 blocksize;
141     cyg_int32 maxfree;                  // The largest free block
142 } cyg_mempool_info;
143
144 /* Puts information about a variable memory pool into the structure
145    provided. */
146 void cyg_mempool_var_get_info(cyg_handle_t varpool, cyg_mempool_info *info) __THROW;
147
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
155     ) __THROW;
156
157 /* Delete fixed size memory pool */
158 void cyg_mempool_fix_delete(cyg_handle_t fixpool) __THROW;
159
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;
164
165 # ifdef CYGFUN_KERNEL_THREADS_TIMER
166
167 /* Allocates a block.  This waits until abstime, if the memory
168    is not already available.  NULL is returned if no memory is
169    available. */
170 void *cyg_mempool_fix_timed_alloc(
171     cyg_handle_t     fixpool,
172     cyg_tick_count_t abstime) __THROW;
173
174 # endif
175 #endif
176
177 /* Allocates a block.  NULL is returned if no memory is available. */
178 void *cyg_mempool_fix_try_alloc(cyg_handle_t fixpool) __THROW;
179
180 /* Frees memory back into fixed size pool. */
181 void cyg_mempool_fix_free(cyg_handle_t fixpool, void *p) __THROW;
182
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;
186
187 /* Puts information about a variable memory pool into the structure
188    provided. */
189 void cyg_mempool_fix_get_info(cyg_handle_t fixpool, cyg_mempool_info *info) __THROW;
190
191 /* user overrideable function invoked before running out of memory. */
192 __externC void cyg_memalloc_alloc_fail(char * file, int line, cyg_int32 size) 
193      __THROW;
194
195 /*---------------------------------------------------------------------------*/
196 #ifdef __cplusplus
197 }
198 #endif
199
200 /*---------------------------------------------------------------------------*/
201
202
203 #endif /* ifndef CYGONCE_MEMALLOC_KAPI_H */
204 /* EOF kapi.h */