Commit 80d19f35 authored by James Brister's avatar James Brister
Browse files

Support ondestroy notification for isc_mem_t.

parent 71a1b26d
......@@ -27,6 +27,8 @@
#include <isc/result.h>
#include <isc/types.h>
#include <isc/ondestroy.h>
ISC_LANG_BEGINDECLS
typedef void * (*isc_memalloc_t)(void *, size_t);
......@@ -53,6 +55,9 @@ typedef void (*isc_memfree_t)(void *, void *);
isc_result_t isc_mem_create(size_t, size_t, isc_mem_t **);
void isc_mem_destroy(isc_mem_t **);
isc_result_t isc_mem_ondestroy(isc_mem_t *ctx,
isc_task_t *task,
isc_event_t **event);
void * __isc_mem_get(isc_mem_t *, size_t);
void __isc_mem_put(isc_mem_t *, void *, size_t);
void * __isc_mem_getdebug(isc_mem_t *, size_t,
......
......@@ -97,6 +97,7 @@ struct stats {
struct isc_mem {
unsigned int magic;
isc_ondestroy_t ondestroy;
isc_mutex_t lock;
isc_memalloc_t memalloc;
isc_memfree_t memfree;
......@@ -248,6 +249,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->quota = 0;
ctx->total = 0;
ctx->magic = MEM_MAGIC;
isc_ondestroy_init(&ctx->ondestroy);
ISC_LIST_INIT(ctx->pools);
*ctxp = ctx;
......@@ -267,6 +269,7 @@ void
isc_mem_destroy(isc_mem_t **ctxp) {
unsigned int i;
isc_mem_t *ctx;
isc_ondestroy_t ondest;
REQUIRE(ctxp != NULL);
ctx = *ctxp;
......@@ -294,12 +297,28 @@ isc_mem_destroy(isc_mem_t **ctxp) {
(ctx->memfree)(ctx->arg, ctx->stats);
(ctx->memfree)(ctx->arg, ctx->basic_table);
ondest = ctx->ondestroy;
(void)isc_mutex_destroy(&ctx->lock);
(ctx->memfree)(ctx->arg, ctx);
isc_ondestroy_notify(&ondest, ctx);
*ctxp = NULL;
}
isc_result_t
isc_mem_ondestroy(isc_mem_t *ctx, isc_task_t *task, isc_event_t **event) {
isc_result_t res;
LOCK(&ctx->lock);
res = isc_ondestroy_register(&ctx->ondestroy, task, event);
UNLOCK(&ctx->lock);
return (res);
}
isc_result_t
isc_mem_restore(isc_mem_t *ctx) {
isc_result_t result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment