mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Support ondestroy notification for isc_mem_t.
This commit is contained in:
parent
71a1b26df0
commit
80d19f3523
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user