From 132cbda37abce5fd5703f696ee8fb42cfd6fd41f Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 12 Jul 2008 09:31:34 +0000 Subject: Ticket 559 (minor): Update the pool alternative API (pool_alt.h) with the latest pool API git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2123 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/pool_alt.h | 69 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'pjlib/include/pj/pool_alt.h') diff --git a/pjlib/include/pj/pool_alt.h b/pjlib/include/pj/pool_alt.h index 9091b854..fb923155 100644 --- a/pjlib/include/pj/pool_alt.h +++ b/pjlib/include/pj/pool_alt.h @@ -22,9 +22,6 @@ #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 @@ -33,6 +30,25 @@ typedef struct pj_pool_t pj_pool_t; */ typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size); +struct pj_pool_mem +{ + struct pj_pool_mem *next; + + /* data follows immediately */ +}; + + +typedef struct pj_pool_t +{ + struct pj_pool_mem *first_mem; + pj_pool_factory *factory; + char obj_name[32]; + pj_size_t used_size; + pj_pool_callback *cb; +} pj_pool_t; + + + /** * This constant denotes the exception number that will be thrown by default * memory factory policy when memory allocation fails. @@ -105,8 +121,54 @@ PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line, pj_pool_t *pool, pj_size_t sz); +#define PJ_POOL_ZALLOC_T(pool,type) \ + ((type*)pj_pool_zalloc(pool, sizeof(type))) +#define PJ_POOL_ALLOC_T(pool,type) \ + ((type*)pj_pool_alloc(pool, sizeof(type))) +#ifndef PJ_POOL_ALIGNMENT +# define PJ_POOL_ALIGNMENT 4 +#endif + +/** + * This structure declares pool factory interface. + */ +typedef struct pj_pool_factory_policy +{ + /** + * Allocate memory block (for use by pool). This function is called + * by memory pool to allocate memory block. + * + * @param factory Pool factory. + * @param size The size of memory block to allocate. + * + * @return Memory block. + */ + void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size); + + /** + * Free memory block. + * + * @param factory Pool factory. + * @param mem Memory block previously allocated by block_alloc(). + * @param size The size of memory block. + */ + void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size); + + /** + * Default callback to be called when memory allocation fails. + */ + pj_pool_callback *callback; + + /** + * Option flags. + */ + unsigned flags; + +} pj_pool_factory_policy; + typedef struct pj_pool_factory { + pj_pool_factory_policy policy; int dummy; } pj_pool_factory; @@ -120,6 +182,5 @@ typedef struct pj_caching_pool #define pj_caching_pool_destroy(cp) #define pj_pool_factory_dump(pf, detail) - #endif /* __PJ_POOL_ALT_H__ */ -- cgit v1.2.3