From f61c7c75c3c7ff4a329315700d3efa1d77bafa6d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 30 May 2014 15:40:46 -0400 Subject: pool: Separate dmnsn_palloc and dmnsn_palloc_tidy() APIs. --- libdimension/dimension/pool.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'libdimension/dimension') diff --git a/libdimension/dimension/pool.h b/libdimension/dimension/pool.h index 33f1dd7..164bbbc 100644 --- a/libdimension/dimension/pool.h +++ b/libdimension/dimension/pool.h @@ -40,18 +40,35 @@ dmnsn_pool *dmnsn_new_pool(void); * Allocate some memory from a pool. * @param[in] pool The memory pool to allocate from. * @param[in] size The size of the memory block to allocate. - * @param[in] callback An optional callback to invoke before the memory is freed. * @return The allocated memory area. */ -void *dmnsn_palloc(dmnsn_pool *pool, size_t size, dmnsn_callback_fn *callback); +void *dmnsn_palloc(dmnsn_pool *pool, size_t size); + +/** + * Allocate some memory from a pool. + * @param[in] pool The memory pool to allocate from. + * @param[in] size The size of the memory block to allocate. + * @param[in] cleanup_fn A callback to invoke before the memory is freed. + * @return The allocated memory area. + */ +void *dmnsn_palloc_tidy(dmnsn_pool *pool, size_t size, dmnsn_callback_fn *cleanup_fn); + +/** + * Allocate some memory from a pool. + * @param[in] pool The memory pool to allocate from. + * @param[in] type The type of the memory block to allocate. + * @return The allocated memory area. + */ +#define DMNSN_PALLOC(pool, type) ((type *)dmnsn_palloc((pool), sizeof(type))) /** * Allocate some memory from a pool. * @param[in] pool The memory pool to allocate from. * @param[in] type The type of the memory block to allocate. + * @param[in] cleanup_fn A callback to invoke before the memory is freed. * @return The allocated memory area. */ -#define DMNSN_PALLOC(pool, type) ((type *)dmnsn_palloc((pool), sizeof(type), NULL)) +#define DMNSN_PALLOC_TIDY(pool, type, cleanup_fn) ((type *)dmnsn_palloc_tidy((pool), sizeof(type), (cleanup_fn))) /** * Free a memory pool and all associated allocations. -- cgit v1.2.3