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;
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  */
Pool_::pb_buffer
PoolBucket * pb_buffer
Definition: util-pool.h:58
Pool_::Free
void(* Free)(void *)
Definition: util-pool.h:64
Pool_::Init
int(* Init)(void *, void *)
Definition: util-pool.h:61
PoolRegisterTests
void PoolRegisterTests(void)
Definition: util-pool.c:715
PoolPrintSaturation
void PoolPrintSaturation(Pool *p)
Definition: util-pool.c:373
Pool_::alloc_stack
PoolBucket * alloc_stack
Definition: util-pool.h:51
Pool_
Definition: util-pool.h:43
Pool_::Cleanup
void(* Cleanup)(void *)
Definition: util-pool.h:63
PoolBucket
struct PoolBucket_ PoolBucket
Pool_::empty_stack_size
uint32_t empty_stack_size
Definition: util-pool.h:54
PoolBucket_::next
struct PoolBucket_ * next
Definition: util-pool.h:39
Pool_::outstanding
uint32_t outstanding
Definition: util-pool.h:67
PoolBucket_::data
void * data
Definition: util-pool.h:37
PoolFree
void PoolFree(Pool *)
Definition: util-pool.c:220
PoolBucket_
Definition: util-pool.h:36
PoolReturn
void PoolReturn(Pool *, void *)
Definition: util-pool.c:333
Pool_::max_buckets
uint32_t max_buckets
Definition: util-pool.h:44
Pool_::preallocated
uint32_t preallocated
Definition: util-pool.h:45
Pool_::allocated
uint32_t allocated
Definition: util-pool.h:46
PoolGet
void * PoolGet(Pool *)
Definition: util-pool.c:275
Pool_::data_buffer_size
int data_buffer_size
Definition: util-pool.h:56
Pool_::empty_stack
PoolBucket * empty_stack
Definition: util-pool.h:53
PoolBucket_::flags
uint8_t flags
Definition: util-pool.h:38
Pool_::elt_size
uint32_t elt_size
Definition: util-pool.h:66
PoolInit
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
Pool_::InitData
void * InitData
Definition: util-pool.h:62
Pool_::alloc_stack_size
uint32_t alloc_stack_size
Definition: util-pool.h:49
Pool_::data_buffer
void * data_buffer
Definition: util-pool.h:57
Pool
struct Pool_ Pool
PoolPrint
void PoolPrint(Pool *)
Definition: util-pool.c:268