BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

pool_alt.h
1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJ_POOL_ALT_H__
21 #define __PJ_POOL_ALT_H__
22 
23 #define __PJ_POOL_H__
24 
26 
33 typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
34 
36 {
37  struct pj_pool_mem *next;
38 
39  /* data follows immediately */
40 };
41 
42 
43 struct pj_pool_t
44 {
45  struct pj_pool_mem *first_mem;
46  pj_pool_factory *factory;
47  char obj_name[32];
48  pj_size_t used_size;
49  pj_pool_callback *cb;
50 };
51 
52 
53 #define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
54 
59 PJ_DECL_DATA(int) PJ_NO_MEMORY_EXCEPTION;
60 
64 PJ_DECL(int) pj_NO_MEMORY_EXCEPTION(void);
65 
66 
67 /*
68  * Declare all pool API as macro that calls the implementation
69  * function.
70  */
71 #define pj_pool_create(fc,nm,init,inc,cb) \
72  pj_pool_create_imp(__FILE__, __LINE__, fc, nm, init, inc, cb)
73 
74 #define pj_pool_release(pool) pj_pool_release_imp(pool)
75 #define pj_pool_safe_release(pool) pj_pool_safe_release_imp(pool)
76 #define pj_pool_secure_release(pool) pj_pool_secure_release_imp(pool)
77 #define pj_pool_getobjname(pool) pj_pool_getobjname_imp(pool)
78 #define pj_pool_reset(pool) pj_pool_reset_imp(pool)
79 #define pj_pool_get_capacity(pool) pj_pool_get_capacity_imp(pool)
80 #define pj_pool_get_used_size(pool) pj_pool_get_used_size_imp(pool)
81 #define pj_pool_alloc(pool,sz) \
82  pj_pool_alloc_imp(__FILE__, __LINE__, pool, sz)
83 
84 #define pj_pool_calloc(pool,cnt,elem) \
85  pj_pool_calloc_imp(__FILE__, __LINE__, pool, cnt, elem)
86 
87 #define pj_pool_zalloc(pool,sz) \
88  pj_pool_zalloc_imp(__FILE__, __LINE__, pool, sz)
89 
90 
91 
92 /*
93  * Declare prototypes for pool implementation API.
94  */
95 
96 /* Create pool */
97 PJ_DECL(pj_pool_t*) pj_pool_create_imp(const char *file, int line,
98  void *factory,
99  const char *name,
100  pj_size_t initial_size,
101  pj_size_t increment_size,
102  pj_pool_callback *callback);
103 
104 /* Release pool */
105 PJ_DECL(void) pj_pool_release_imp(pj_pool_t *pool);
106 
107 /* Safe release pool */
108 PJ_DECL(void) pj_pool_safe_release_imp(pj_pool_t **pool);
109 
110 /* Secure release pool */
111 PJ_DECL(void) pj_pool_secure_release_imp(pj_pool_t **pool);
112 
113 /* Get pool name */
114 PJ_DECL(const char*) pj_pool_getobjname_imp(pj_pool_t *pool);
115 
116 /* Reset pool */
117 PJ_DECL(void) pj_pool_reset_imp(pj_pool_t *pool);
118 
119 /* Get capacity */
120 PJ_DECL(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool);
121 
122 /* Get total used size */
123 PJ_DECL(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool);
124 
125 /* Allocate memory from the pool */
126 PJ_DECL(void*) pj_pool_alloc_imp(const char *file, int line,
127  pj_pool_t *pool, pj_size_t sz);
128 
129 /* Allocate memory from the pool and zero the memory */
130 PJ_DECL(void*) pj_pool_calloc_imp(const char *file, int line,
131  pj_pool_t *pool, unsigned cnt,
132  unsigned elemsz);
133 
134 /* Allocate memory from the pool and zero the memory */
135 PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line,
136  pj_pool_t *pool, pj_size_t sz);
137 
138 
139 #define PJ_POOL_ZALLOC_T(pool,type) \
140  ((type*)pj_pool_zalloc(pool, sizeof(type)))
141 #define PJ_POOL_ALLOC_T(pool,type) \
142  ((type*)pj_pool_alloc(pool, sizeof(type)))
143 #ifndef PJ_POOL_ALIGNMENT
144 # define PJ_POOL_ALIGNMENT 4
145 #endif
146 
150 typedef struct pj_pool_factory_policy
151 {
161  void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
162 
170  void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
171 
175  pj_pool_callback *callback;
176 
180  unsigned flags;
181 
183 
184 struct pj_pool_factory
185 {
186  pj_pool_factory_policy policy;
187  int dummy;
188 };
189 
190 struct pj_caching_pool
191 {
192  pj_pool_factory factory;
193 
194  /* just to make it compilable */
195  unsigned used_count;
196  unsigned used_size;
197  unsigned peak_used_size;
198 };
199 
200 /* just to make it compilable */
201 typedef struct pj_pool_block
202 {
203  int dummy;
204 } pj_pool_block;
205 
206 #define pj_caching_pool_init( cp, pol, mac)
207 #define pj_caching_pool_destroy(cp)
208 #define pj_pool_factory_dump(pf, detail)
209 
211 
212 #endif /* __PJ_POOL_ALT_H__ */
213 
Definition: pool.h:823
int pj_NO_MEMORY_EXCEPTION(void)
Definition: pool_alt.h:35
Definition: pool.h:666
#define PJ_END_DECL
Definition: config.h:1281
Definition: pool.h:297
#define PJ_BEGIN_DECL
Definition: config.h:1280
Definition: pool.h:310
Definition: pool.h:595
void pj_pool_callback(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:291
size_t pj_size_t
Definition: types.h:58

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.