diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-03-30 15:56:01 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-03-30 15:56:01 +0000 |
commit | 3cf609b42e573adf8e7183070176a450a7b4959e (patch) | |
tree | 3a34159d7b023de27b99675520ab8f82e4245027 /pjlib/include/pj/pool_alt.h | |
parent | e985f59aabf893535e0d12c5867e44d69ccb83fe (diff) |
Added ability to have custom pool backend (needed for pool debugging facility)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@364 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include/pj/pool_alt.h')
-rw-r--r-- | pjlib/include/pj/pool_alt.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/pjlib/include/pj/pool_alt.h b/pjlib/include/pj/pool_alt.h new file mode 100644 index 00000000..a0929dc7 --- /dev/null +++ b/pjlib/include/pj/pool_alt.h @@ -0,0 +1,125 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJ_POOL_ALT_H__ +#define __PJ_POOL_ALT_H__ + +#define __PJ_POOL_H__ + + +typedef struct pj_pool_t pj_pool_t; + + +/** + * The type for function to receive callback from the pool when it is unable + * to allocate memory. The elegant way to handle this condition is to throw + * exception, and this is what is expected by most of this library + * components. + */ +typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size); + +/** + * This constant denotes the exception number that will be thrown by default + * memory factory policy when memory allocation fails. + */ +extern int PJ_NO_MEMORY_EXCEPTION; + + + +/* + * Declare all pool API as macro that calls the implementation + * function. + */ +#define pj_pool_create(fc,nm,init,inc,cb) \ + pj_pool_create_imp(__FILE__, __LINE__, fc, nm, init, inc, cb) + +#define pj_pool_release(pool) pj_pool_release_imp(pool) +#define pj_pool_getobjname(pool) pj_pool_getobjname_imp(pool) +#define pj_pool_reset(pool) pj_pool_reset_imp(pool) +#define pj_pool_get_capacity(pool) pj_pool_get_capacity_imp(pool) +#define pj_pool_get_used_size(pool) pj_pool_get_used_size_imp(pool) +#define pj_pool_alloc(pool,sz) \ + pj_pool_alloc_imp(__FILE__, __LINE__, pool, sz) + +#define pj_pool_calloc(pool,cnt,elem) \ + pj_pool_calloc_imp(__FILE__, __LINE__, pool, cnt, elem) + +#define pj_pool_zalloc(pool,sz) \ + pj_pool_zalloc_imp(__FILE__, __LINE__, pool, sz) + + + +/* + * Declare prototypes for pool implementation API. + */ + +/* Create pool */ +PJ_DECL(pj_pool_t*) pj_pool_create_imp(const char *file, int line, + void *factory, + const char *name, + pj_size_t initial_size, + pj_size_t increment_size, + pj_pool_callback *callback); + +/* Release pool */ +PJ_DECL(void) pj_pool_release_imp(pj_pool_t *pool); + +/* Get pool name */ +PJ_DECL(const char*) pj_pool_getobjname_imp(pj_pool_t *pool); + +/* Reset pool */ +PJ_DECL(void) pj_pool_reset_imp(pj_pool_t *pool); + +/* Get capacity */ +PJ_DECL(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool); + +/* Get total used size */ +PJ_DECL(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool); + +/* Allocate memory from the pool */ +PJ_DECL(void*) pj_pool_alloc_imp(const char *file, int line, + pj_pool_t *pool, pj_size_t sz); + +/* Allocate memory from the pool and zero the memory */ +PJ_DECL(void*) pj_pool_calloc_imp(const char *file, int line, + pj_pool_t *pool, unsigned cnt, + unsigned elemsz); + +/* Allocate memory from the pool and zero the memory */ +PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line, + pj_pool_t *pool, pj_size_t sz); + + +typedef struct pj_pool_factory +{ + int dummy; +} pj_pool_factory; + +typedef struct pj_caching_pool +{ + pj_pool_factory factory; +} pj_caching_pool; + + +#define pj_caching_pool_init( cp, pol, mac) +#define pj_caching_pool_destroy(cp) +#define pj_pool_factory_dump(pf, detail) + + +#endif /* __PJ_POOL_ALT_H__ */ + |