BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

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

 


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