void pool_flush(struct pool_head *pool);
void pool_gc(struct pool_head *pool_ctx);
struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
+struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg);
void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
void *pool_destroy(struct pool_head *pool);
void pool_destroy_all(void);
*/
struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
{
- unsigned int extra_mark, extra_caller, extra;
struct pool_registration *reg;
struct pool_head *pool;
- struct pool_head *entry;
- struct list *start;
- unsigned int align;
- unsigned int best_diff;
- int thr __maybe_unused;
- pool = NULL;
reg = calloc(1, sizeof(*reg));
if (!reg)
- goto fail;
+ return NULL;
strlcpy2(reg->name, name, sizeof(reg->name));
reg->size = size;
reg->flags = flags;
reg->align = 0;
+ pool = create_pool_from_reg(name, reg);
+ if (!pool)
+ free(reg);
+ return pool;
+}
+
+/* create a pool from a pool registration. All configuration is taken from
+ * there.
+ */
+struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg)
+{
+ unsigned int extra_mark, extra_caller, extra;
+ unsigned int flags = reg->flags;
+ unsigned int size = reg->size;
+ struct pool_head *pool = NULL;
+ struct pool_head *entry;
+ struct list *start;
+ unsigned int align;
+ unsigned int best_diff;
+ int thr __maybe_unused;
+
extra_mark = (pool_debugging & POOL_DBG_TAG) ? POOL_EXTRA_MARK : 0;
extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
extra = extra_mark + extra_caller;
pool->users++;
pool->sum_size += size;
- return pool;
fail:
- free(reg);
- return NULL;
+ return pool;
}
/* Tries to allocate an object for the pool <pool> using the system's allocator