fragpool  20170302
Variable-sized packet memory management for embedded applications
fragpool.h
Go to the documentation of this file.
1 /* Copyright 2012-2017, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef FRAGPOOL_H_
33 #define FRAGPOOL_H_
34 
88 #include <stdint.h>
89 
91 #define FP_VERSION 20170302
92 
97 typedef uint16_t fp_size_t;
98 
101 typedef int16_t fp_ssize_t;
102 
105 #define FP_MAX_FRAGMENT_SIZE INT16_MAX
106 
109 #define FP_EINVAL 1
110 
122 typedef struct fp_fragment_t {
125  uint8_t* start;
126 
131 } *fp_fragment_t;
132 
165 #define FP_POOL_STRUCT_COMMON \
166  uint8_t* pool_start; \
167  uint8_t* pool_end; \
168  uint8_t pool_alignment; \
169  uint8_t fragment_count
170 
171 #ifdef FP_DOXYGEN
172 
180  uint8_t* pool_start;
181 
184  uint8_t* pool_end;
185 
190  uint8_t pool_alignment;
191 
193  uint8_t fragment_count;
194 };
195 #endif /* FP_DOXYGEN */
196 
203 typedef struct fp_pool_t {
205 
215  struct fp_fragment_t fragment[];
216 } *fp_pool_t;
217 
225 void fp_reset (fp_pool_t pool);
226 
253 uint8_t* fp_request (fp_pool_t pool,
254  fp_size_t min_size,
255  fp_size_t max_size,
256  uint8_t** fragment_endp);
257 
295 uint8_t* fp_resize (fp_pool_t pool,
296  uint8_t* bp,
297  fp_size_t new_size,
298  uint8_t** fragment_endp);
299 
336 uint8_t* fp_reallocate (fp_pool_t pool,
337  uint8_t* bp,
338  fp_size_t min_size,
339  fp_size_t max_size,
340  uint8_t** fragment_endp);
341 
351 int fp_release (fp_pool_t pool,
352  const uint8_t* bp);
353 
360 int fp_validate (const fp_pool_t pool);
361 
362 #endif /* FRAGPOOL_H_ */
uint8_t * pool_end
Definition: fragpool.h:184
uint16_t fp_size_t
Definition: fragpool.h:97
uint8_t fragment_count
Definition: fragpool.h:193
uint8_t * fp_request(fp_pool_t pool, fp_size_t min_size, fp_size_t max_size, uint8_t **fragment_endp)
#define FP_POOL_STRUCT_COMMON
Definition: fragpool.h:165
uint8_t * start
Definition: fragpool.h:125
struct fp_fragment_t * fp_fragment_t
uint8_t * fp_reallocate(fp_pool_t pool, uint8_t *bp, fp_size_t min_size, fp_size_t max_size, uint8_t **fragment_endp)
void fp_reset(fp_pool_t pool)
int fp_validate(const fp_pool_t pool)
Definition: fragpool.h:178
struct fp_pool_t * fp_pool_t
int16_t fp_ssize_t
Definition: fragpool.h:101
uint8_t * pool_start
Definition: fragpool.h:180
uint8_t * fp_resize(fp_pool_t pool, uint8_t *bp, fp_size_t new_size, uint8_t **fragment_endp)
Definition: fragpool.h:203
uint8_t pool_alignment
Definition: fragpool.h:190
Definition: fragpool.h:122
int fp_release(fp_pool_t pool, const uint8_t *bp)
fp_ssize_t length
Definition: fragpool.h:130