suricata
util-pool.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2010 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \ingroup utilpool
20 *
21 * @{
22 */
23
24/**
25 * \file
26 *
27 * \author Victor Julien <victor@inliniac.net>
28 */
29
30#ifndef SURICATA_UTIL_POOL_H
31#define SURICATA_UTIL_POOL_H
32
33#define POOL_BUCKET_PREALLOCATED (1 << 0)
34
35/* pool bucket structure */
36typedef struct PoolBucket_ {
37 void *data;
38 uint8_t flags;
41
42/* pool structure */
43typedef struct Pool_ {
44 uint32_t max_buckets;
45 uint32_t preallocated;
46 uint32_t allocated; /**< counter of data elements, both currently in
47 * the pool and outside of it (outstanding) */
48
50
52
55
59
60 void *(*Alloc)(void);
61 int (*Init)(void *, void *);
62 void *InitData;
63 void (*Cleanup)(void *);
64 void (*Free)(void *);
65
66 uint32_t elt_size;
67 uint32_t outstanding; /**< counter of data items 'in use'. Pretty much
68 * the diff between PoolGet and PoolReturn */
69#ifdef DEBUG
70 uint32_t max_outstanding; /**< max value of outstanding we saw */
71#endif
73
74/* prototypes */
75Pool* PoolInit(uint32_t, uint32_t, uint32_t, void *(*Alloc)(void), int (*Init)(void *, void *), void *, void (*Cleanup)(void *), void (*Free)(void *));
76void PoolFree(Pool *);
77
78void *PoolGet(Pool *);
79void PoolReturn(Pool *, void *);
80
81void PoolRegisterTests(void);
82
83#endif /* SURICATA_UTIL_POOL_H */
84
85/**
86 * @}
87 */
void PoolFree(Pool *)
Definition util-pool.c:223
Pool * PoolInit(uint32_t, uint32_t, uint32_t, void *(*Alloc)(void), int(*Init)(void *, void *), void *, void(*Cleanup)(void *), void(*Free)(void *))
Init a Pool.
Definition util-pool.c:84
void PoolReturn(Pool *, void *)
Definition util-pool.c:329
void PoolRegisterTests(void)
Definition util-pool.c:705
void * PoolGet(Pool *)
Definition util-pool.c:271
void * data
Definition util-pool.h:37
struct PoolBucket_ * next
Definition util-pool.h:39
uint8_t flags
Definition util-pool.h:38
uint32_t alloc_stack_size
Definition util-pool.h:49
uint32_t max_buckets
Definition util-pool.h:44
PoolBucket * empty_stack
Definition util-pool.h:53
void(* Cleanup)(void *)
Definition util-pool.h:63
int(* Init)(void *, void *)
Definition util-pool.h:61
uint32_t allocated
Definition util-pool.h:46
uint32_t preallocated
Definition util-pool.h:45
uint32_t elt_size
Definition util-pool.h:66
int data_buffer_size
Definition util-pool.h:56
PoolBucket * pb_buffer
Definition util-pool.h:58
uint32_t empty_stack_size
Definition util-pool.h:54
void * InitData
Definition util-pool.h:62
uint32_t outstanding
Definition util-pool.h:67
void * data_buffer
Definition util-pool.h:57
void(* Free)(void *)
Definition util-pool.h:64
PoolBucket * alloc_stack
Definition util-pool.h:51
struct PoolBucket_ PoolBucket
struct Pool_ Pool