The Pedigree Project  0.1
memp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Adam Dunkels <adam@sics.se>
54  *
55  */
56 
57 #ifndef LWIP_HDR_MEMP_H
58 #define LWIP_HDR_MEMP_H
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* run once with empty definition to handle all custom includes in lwippools.h */
65 #define LWIP_MEMPOOL(name,num,size,desc)
66 #include "lwip/priv/memp_std.h"
67 
69 typedef enum {
70 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
71 #include "lwip/priv/memp_std.h"
72  MEMP_MAX
73 } memp_t;
74 
75 #include "lwip/priv/memp_priv.h"
76 #include "lwip/stats.h"
77 
78 extern const struct memp_desc* const memp_pools[MEMP_MAX];
79 
84 #define LWIP_MEMPOOL_PROTOTYPE(name) extern const struct memp_desc memp_ ## name
85 
86 #if MEMP_MEM_MALLOC
87 
88 #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
89  LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) \
90  const struct memp_desc memp_ ## name = { \
91  DECLARE_LWIP_MEMPOOL_DESC(desc) \
92  LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \
93  LWIP_MEM_ALIGN_SIZE(size) \
94  };
95 
96 #else /* MEMP_MEM_MALLOC */
97 
112 #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
113  LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \
114  \
115  LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) \
116  \
117  static struct memp *memp_tab_ ## name; \
118  \
119  const struct memp_desc memp_ ## name = { \
120  DECLARE_LWIP_MEMPOOL_DESC(desc) \
121  LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \
122  LWIP_MEM_ALIGN_SIZE(size), \
123  (num), \
124  memp_memory_ ## name ## _base, \
125  &memp_tab_ ## name \
126  };
127 
128 #endif /* MEMP_MEM_MALLOC */
129 
134 #define LWIP_MEMPOOL_INIT(name) memp_init_pool(&memp_ ## name)
135 
139 #define LWIP_MEMPOOL_ALLOC(name) memp_malloc_pool(&memp_ ## name)
140 
144 #define LWIP_MEMPOOL_FREE(name, x) memp_free_pool(&memp_ ## name, (x))
145 
146 #if MEM_USE_POOLS
147 
149 struct memp_malloc_helper
150 {
151  memp_t poolnr;
152 #if MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS)
153  u16_t size;
154 #endif /* MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS) */
155 };
156 #endif /* MEM_USE_POOLS */
157 
158 void memp_init(void);
159 
160 #if MEMP_OVERFLOW_CHECK
161 void *memp_malloc_fn(memp_t type, const char* file, const int line);
162 #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
163 #else
164 void *memp_malloc(memp_t type);
165 #endif
166 void memp_free(memp_t type, void *mem);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif /* LWIP_HDR_MEMP_H */
memp_t
Definition: memp.h:69
void * memp_malloc(memp_t type)
Definition: memp.c:404
void memp_free(memp_t type, void *mem)
Definition: memp.c:488
void memp_init(void)
Definition: memp.c:290
Definition: mem.c:283