mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-23 23:28:18 -04:00
New function isc_mem_putanddetach().
This commit is contained in:
parent
fa263add26
commit
1162a4e02a
2 changed files with 50 additions and 2 deletions
|
|
@ -15,7 +15,7 @@
|
|||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: mem.h,v 1.42 2000/08/31 16:58:28 gson Exp $ */
|
||||
/* $Id: mem.h,v 1.43 2000/09/05 03:30:19 marka Exp $ */
|
||||
|
||||
#ifndef ISC_MEM_H
|
||||
#define ISC_MEM_H 1
|
||||
|
|
@ -102,6 +102,11 @@ extern unsigned int isc_mem_debugging;
|
|||
isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putanddetach(c, p, s) \
|
||||
do { \
|
||||
isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_free(c, p) \
|
||||
do { \
|
||||
isc__mem_free((c), (p) _ISC_MEM_FILELINE); \
|
||||
|
|
@ -114,6 +119,8 @@ extern unsigned int isc_mem_debugging;
|
|||
} while (0)
|
||||
#else
|
||||
#define isc_mem_put(c, p, s) isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE)
|
||||
#define isc_mem_putanddetach(c, p, s) \
|
||||
isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE)
|
||||
#define isc_mem_free(c, p) isc__mem_free((c), (p) _ISC_MEM_FILELINE)
|
||||
#define isc_mempool_put(c, p) isc__mempool_put((c), (p) _ISC_MEM_FILELINE)
|
||||
#endif
|
||||
|
|
@ -127,6 +134,8 @@ isc_result_t isc_mem_ondestroy(isc_mem_t *ctx,
|
|||
isc_event_t **event);
|
||||
void * isc__mem_get(isc_mem_t *, size_t
|
||||
_ISC_MEM_FLARG);
|
||||
void isc__mem_putanddetach(isc_mem_t **, void *,
|
||||
size_t _ISC_MEM_FLARG);
|
||||
void isc__mem_put(isc_mem_t *, void *,
|
||||
size_t _ISC_MEM_FLARG);
|
||||
isc_result_t isc_mem_preallocate(isc_mem_t *);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: mem.c,v 1.61 2000/08/31 12:15:16 marka Exp $ */
|
||||
/* $Id: mem.c,v 1.62 2000/09/05 03:30:18 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -755,6 +755,45 @@ isc_mem_detach(isc_mem_t **ctxp) {
|
|||
*ctxp = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* isc_mem_putanddetach() is the equivalent of:
|
||||
*
|
||||
* mctx = NULL;
|
||||
* isc_mem_attach(ptr->mctx, &mctx);
|
||||
* isc_mem_detach(&ptr->mctx);
|
||||
* isc_mem_put(mctx, ptr, sizeof(*ptr);
|
||||
* isc_mem_detach(&mctx);
|
||||
*/
|
||||
|
||||
void
|
||||
isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
|
||||
isc_mem_t *ctx;
|
||||
isc_boolean_t want_destroy = ISC_FALSE;
|
||||
|
||||
REQUIRE(ctxp != NULL);
|
||||
ctx = *ctxp;
|
||||
REQUIRE(VALID_CONTEXT(ctx));
|
||||
REQUIRE(ptr != NULL);
|
||||
|
||||
/*
|
||||
* Must be before mem_putunlocked() as ctxp is usually within
|
||||
* [ptr..ptr+size).
|
||||
*/
|
||||
*ctxp = NULL;
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
DELETE_TRACE(ctx, ptr, size, file, line);
|
||||
mem_putunlocked(ctx, ptr, size);
|
||||
INSIST(ctx->references > 0);
|
||||
ctx->references--;
|
||||
if (ctx->references == 0)
|
||||
want_destroy = ISC_TRUE;
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
if (want_destroy)
|
||||
destroy(ctx);
|
||||
}
|
||||
|
||||
void
|
||||
isc_mem_destroy(isc_mem_t **ctxp) {
|
||||
isc_mem_t *ctx;
|
||||
|
|
|
|||
Loading…
Reference in a new issue