blob: 9091b8545295735ee0ad412193b0c001e66cd802 [file] [log] [blame]
Benny Prijono8508aa02006-03-30 15:56:01 +00001/* $Id$ */
2/*
Benny Prijono32177c02008-06-20 22:44:47 +00003 * Copyright (C)2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono8508aa02006-03-30 15:56:01 +00004 *
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
24
25typedef struct pj_pool_t pj_pool_t;
26
27
28/**
29 * The type for function to receive callback from the pool when it is unable
30 * to allocate memory. The elegant way to handle this condition is to throw
31 * exception, and this is what is expected by most of this library
32 * components.
33 */
34typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
35
36/**
37 * This constant denotes the exception number that will be thrown by default
38 * memory factory policy when memory allocation fails.
39 */
40extern int PJ_NO_MEMORY_EXCEPTION;
41
42
43
44/*
45 * Declare all pool API as macro that calls the implementation
46 * function.
47 */
48#define pj_pool_create(fc,nm,init,inc,cb) \
49 pj_pool_create_imp(__FILE__, __LINE__, fc, nm, init, inc, cb)
50
51#define pj_pool_release(pool) pj_pool_release_imp(pool)
52#define pj_pool_getobjname(pool) pj_pool_getobjname_imp(pool)
53#define pj_pool_reset(pool) pj_pool_reset_imp(pool)
54#define pj_pool_get_capacity(pool) pj_pool_get_capacity_imp(pool)
55#define pj_pool_get_used_size(pool) pj_pool_get_used_size_imp(pool)
56#define pj_pool_alloc(pool,sz) \
57 pj_pool_alloc_imp(__FILE__, __LINE__, pool, sz)
58
59#define pj_pool_calloc(pool,cnt,elem) \
60 pj_pool_calloc_imp(__FILE__, __LINE__, pool, cnt, elem)
61
62#define pj_pool_zalloc(pool,sz) \
63 pj_pool_zalloc_imp(__FILE__, __LINE__, pool, sz)
64
65
66
67/*
68 * Declare prototypes for pool implementation API.
69 */
70
71/* Create pool */
72PJ_DECL(pj_pool_t*) pj_pool_create_imp(const char *file, int line,
73 void *factory,
74 const char *name,
75 pj_size_t initial_size,
76 pj_size_t increment_size,
77 pj_pool_callback *callback);
78
79/* Release pool */
80PJ_DECL(void) pj_pool_release_imp(pj_pool_t *pool);
81
82/* Get pool name */
83PJ_DECL(const char*) pj_pool_getobjname_imp(pj_pool_t *pool);
84
85/* Reset pool */
86PJ_DECL(void) pj_pool_reset_imp(pj_pool_t *pool);
87
88/* Get capacity */
89PJ_DECL(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool);
90
91/* Get total used size */
92PJ_DECL(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool);
93
94/* Allocate memory from the pool */
95PJ_DECL(void*) pj_pool_alloc_imp(const char *file, int line,
96 pj_pool_t *pool, pj_size_t sz);
97
98/* Allocate memory from the pool and zero the memory */
99PJ_DECL(void*) pj_pool_calloc_imp(const char *file, int line,
100 pj_pool_t *pool, unsigned cnt,
101 unsigned elemsz);
102
103/* Allocate memory from the pool and zero the memory */
104PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line,
105 pj_pool_t *pool, pj_size_t sz);
106
107
108typedef struct pj_pool_factory
109{
110 int dummy;
111} pj_pool_factory;
112
113typedef struct pj_caching_pool
114{
115 pj_pool_factory factory;
116} pj_caching_pool;
117
118
119#define pj_caching_pool_init( cp, pol, mac)
120#define pj_caching_pool_destroy(cp)
121#define pj_pool_factory_dump(pf, detail)
122
123
124#endif /* __PJ_POOL_ALT_H__ */
125