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 __UTIL_POOL_H__
31 #define __UTIL_POOL_H__
32 
33 #define POOL_BUCKET_PREALLOCATED (1 << 0)
34 
35 /* pool bucket structure */
36 typedef struct PoolBucket_ {
37  void *data;
38  uint8_t flags;
39  struct PoolBucket_ *next;
40 } PoolBucket;
41 
42 /* pool structure */
43 typedef 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 
49  uint32_t alloc_stack_size;
50 
52 
54  uint32_t empty_stack_size;
55 
57  void *data_buffer;
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
72 } Pool;
73 
74 /* prototypes */
75 Pool* PoolInit(uint32_t, uint32_t, uint32_t, void *(*Alloc)(void), int (*Init)(void *, void *), void *, void (*Cleanup)(void *), void (*Free)(void *));
76 void PoolFree(Pool *);
77 void PoolPrint(Pool *);
78 void PoolPrintSaturation(Pool *p);
79 
80 void *PoolGet(Pool *);
81 void PoolReturn(Pool *, void *);
82 
83 void PoolRegisterTests(void);
84 
85 #endif /* __UTIL_POOL_H__ */
86 
87 /**
88  * @}
89  */
uint32_t empty_stack_size
Definition: util-pool.h:54
uint32_t allocated
Definition: util-pool.h:46
struct Pool_ Pool
void PoolRegisterTests(void)
Definition: util-pool.c:715
uint32_t elt_size
Definition: util-pool.h:66
void PoolPrintSaturation(Pool *p)
Definition: util-pool.c:373
void * data_buffer
Definition: util-pool.h:57
uint32_t alloc_stack_size
Definition: util-pool.h:49
void * data
Definition: util-pool.h:37
uint32_t preallocated
Definition: util-pool.h:45
uint8_t flags
Definition: util-pool.h:38
uint32_t outstanding
Definition: util-pool.h:67
PoolBucket * alloc_stack
Definition: util-pool.h:51
void PoolReturn(Pool *, void *)
Definition: util-pool.c:333
void PoolFree(Pool *)
Definition: util-pool.c:220
uint32_t max_buckets
Definition: util-pool.h:44
PoolBucket * empty_stack
Definition: util-pool.h:53
struct PoolBucket_ PoolBucket
void * PoolGet(Pool *)
Definition: util-pool.c:275
struct PoolBucket_ * next
Definition: util-pool.h:39
int data_buffer_size
Definition: util-pool.h:56
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 * InitData
Definition: util-pool.h:62
void PoolPrint(Pool *)
Definition: util-pool.c:268
PoolBucket * pb_buffer
Definition: util-pool.h:58