diff options
author | Internet Software Consortium, Inc <@isc.org> | 2007-09-07 14:08:19 -0600 |
---|---|---|
committer | LaMont Jones <lamont@debian.org> | 2007-09-07 14:08:19 -0600 |
commit | 93744e253a50cdd78097dc5a150f4c035e8cbcc9 (patch) | |
tree | f7470097a04345f967281dd4d658dd065c51d166 /lib/isc/mem.c | |
parent | 6257efc35455318993208bef65a551ac6039f51f (diff) | |
download | bind9-93744e253a50cdd78097dc5a150f4c035e8cbcc9.tar.gz |
9.0.0b3
Diffstat (limited to 'lib/isc/mem.c')
-rw-r--r-- | lib/isc/mem.c | 476 |
1 files changed, 340 insertions, 136 deletions
diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 2e868420..d19a2358 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -20,13 +20,12 @@ #include <stdio.h> #include <stdlib.h> #include <stddef.h> -#include <string.h> #include <limits.h> -#include <isc/assertions.h> -#include <isc/error.h> #include <isc/mem.h> +#include <isc/ondestroy.h> +#include <isc/string.h> #ifndef ISC_SINGLETHREADED #include <isc/mutex.h> @@ -112,9 +111,12 @@ struct isc_mem { unsigned char * lowest; unsigned char * highest; isc_boolean_t checkfree; + isc_boolean_t trysplit; struct stats * stats; + unsigned int references; size_t quota; size_t total; + size_t inuse; ISC_LIST(isc_mempool_t) pools; }; @@ -224,6 +226,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, return (ISC_R_NOMEMORY); } ctx->checkfree = ISC_TRUE; + ctx->trysplit = ISC_FALSE; memset(ctx->freelists, 0, ctx->max_size * sizeof (element *)); ctx->stats = (memalloc)(arg, @@ -248,8 +251,10 @@ isc_mem_createx(size_t init_max_size, size_t target_size, "isc_mutex_init() failed"); return (ISC_R_UNEXPECTED); } + ctx->references = 1; ctx->quota = 0; ctx->total = 0; + ctx->inuse = 0; ctx->magic = MEM_MAGIC; isc_ondestroy_init(&ctx->ondestroy); ISC_LIST_INIT(ctx->pools); @@ -267,19 +272,15 @@ isc_mem_create(size_t init_max_size, size_t target_size, ctxp)); } -void -isc_mem_destroy(isc_mem_t **ctxp) { +static void +destroy(isc_mem_t *ctx) { unsigned int i; - isc_mem_t *ctx; isc_ondestroy_t ondest; - REQUIRE(ctxp != NULL); - ctx = *ctxp; - REQUIRE(VALID_CONTEXT(ctx)); - ctx->magic = 0; INSIST(ISC_LIST_EMPTY(ctx->pools)); + INSIST(ctx->references == 0); if (ctx->checkfree) { for (i = 0; i <= ctx->max_size; i++) @@ -305,6 +306,65 @@ isc_mem_destroy(isc_mem_t **ctxp) { (ctx->memfree)(ctx->arg, ctx); isc_ondestroy_notify(&ondest, ctx); +} + +void +isc_mem_attach(isc_mem_t *source, isc_mem_t **targetp) { + REQUIRE(VALID_CONTEXT(source)); + REQUIRE(targetp != NULL && *targetp == NULL); + + LOCK(&source->lock); + source->references++; + UNLOCK(&source->lock); + + *targetp = source; +} + +void +isc_mem_detach(isc_mem_t **ctxp) { + isc_mem_t *ctx; + isc_boolean_t want_destroy = ISC_FALSE; + + REQUIRE(ctxp != NULL); + ctx = *ctxp; + REQUIRE(VALID_CONTEXT(ctx)); + + LOCK(&ctx->lock); + INSIST(ctx->references > 0); + ctx->references--; + if (ctx->references == 0) + want_destroy = ISC_TRUE; + UNLOCK(&ctx->lock); + + if (want_destroy) + destroy(ctx); + + *ctxp = NULL; +} + +void +isc_mem_destroy(isc_mem_t **ctxp) { + isc_mem_t *ctx; + isc_boolean_t want_destroy = ISC_FALSE; + + /* + * This routine provides legacy support for callers who use mctxs + * without attaching/detaching. + */ + + REQUIRE(ctxp != NULL); + ctx = *ctxp; + REQUIRE(VALID_CONTEXT(ctx)); + + LOCK(&ctx->lock); + REQUIRE(ctx->references == 1); + ctx->references--; + if (ctx->references == 0) + want_destroy = ISC_TRUE; + UNLOCK(&ctx->lock); + + if (want_destroy) + destroy(ctx); *ctxp = NULL; } @@ -332,7 +392,7 @@ isc_mem_restore(isc_mem_t *ctx) { return (result); } -static void +static inline isc_boolean_t more_basic_blocks(isc_mem_t *ctx) { void *new; unsigned char *curr, *next; @@ -349,7 +409,7 @@ more_basic_blocks(isc_mem_t *ctx) { */ increment = NUM_BASIC_BLOCKS * ctx->mem_target; if (ctx->quota != 0 && ctx->total + increment > ctx->quota) - return; + return (ISC_FALSE); INSIST(ctx->basic_table_count <= ctx->basic_table_size); if (ctx->basic_table_count == ctx->basic_table_size) { @@ -357,7 +417,7 @@ more_basic_blocks(isc_mem_t *ctx) { table = (ctx->memalloc)(ctx->arg, table_size * sizeof (unsigned char *)); if (table == NULL) - return; + return (ISC_FALSE); if (ctx->basic_table_size != 0) { memcpy(table, ctx->basic_table, ctx->basic_table_size * @@ -370,7 +430,7 @@ more_basic_blocks(isc_mem_t *ctx) { new = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target); if (new == NULL) - return; + return (ISC_FALSE); ctx->total += increment; ctx->basic_table[ctx->basic_table_count] = new; ctx->basic_table_count++; @@ -394,11 +454,12 @@ more_basic_blocks(isc_mem_t *ctx) { if (last > ctx->highest) ctx->highest = last; ctx->basic_blocks = new; + + return (ISC_TRUE); } void * -__isc_mem_get(isc_mem_t *ctx, size_t size) -{ +isc__mem_get(isc_mem_t *ctx, size_t size) { void *ret; REQUIRE(VALID_CONTEXT(ctx)); @@ -410,6 +471,7 @@ __isc_mem_get(isc_mem_t *ctx, size_t size) return (ret); } +#if ISC_MEM_FILL != 0 && ISC_MEM_CHECKOVERRUN != 0 static inline void check_overrun(void *mem, size_t size, size_t new_size) { unsigned char *cp; @@ -422,15 +484,137 @@ check_overrun(void *mem, size_t size, size_t new_size) { size++; } } +#endif + +static inline void +split(isc_mem_t *ctx, size_t size, size_t new_size) { + unsigned char *ptr; + size_t remaining_size; + + /* + * Unlink a frag of size 'size'. + */ + ptr = (unsigned char *)ctx->freelists[size]; + ctx->freelists[size] = ctx->freelists[size]->next; + ctx->stats[size].freefrags--; + + /* + * Create a frag of size 'new_size' and link it in. + */ + ((element *)ptr)->next = ctx->freelists[new_size]; + ctx->freelists[new_size] = (element *)ptr; + ctx->stats[new_size].freefrags++; + + /* + * Create a frag of size 'size - new_size' and link it in. + */ + remaining_size = size - new_size; + ptr += new_size; + ((element *)ptr)->next = ctx->freelists[remaining_size]; + ctx->freelists[remaining_size] = (element *)ptr; + ctx->stats[remaining_size].freefrags++; +} + +static inline isc_boolean_t +try_split(isc_mem_t *ctx, size_t new_size) { + size_t i, doubled_size; + + if (!ctx->trysplit) + return (ISC_FALSE); + + /* + * Try splitting a frag that's at least twice as big as the size + * we want. + */ + doubled_size = new_size * 2; + for (i = doubled_size; + i < ctx->max_size; + i += ALIGNMENT_SIZE) { + if (ctx->freelists[i] != NULL) { + split(ctx, i, new_size); + return (ISC_TRUE); + } + } + + /* + * No luck. Try splitting any frag bigger than the size we need. + */ + for (i = new_size + ALIGNMENT_SIZE; + i < doubled_size; + i += ALIGNMENT_SIZE) { + if (ctx->freelists[i] != NULL) { + split(ctx, i, new_size); + return (ISC_TRUE); + } + } + + return (ISC_FALSE); +} + +static inline isc_boolean_t +more_frags(isc_mem_t *ctx, size_t new_size) { + int i, frags; + size_t total_size; + void *new; + unsigned char *curr, *next; + + /* + * Try to get more fragments by chopping up a basic block. + */ + + if (ctx->basic_blocks == NULL) { + if (!more_basic_blocks(ctx)) { + /* + * We can't get more memory from the OS, or we've + * hit the quota for this context. + */ + /* + * XXXRTH "At quota" notification here. + */ + /* + * Maybe we can split one of our existing + * list frags. + */ + return (try_split(ctx, new_size)); + } + } + + total_size = ctx->mem_target; + new = ctx->basic_blocks; + ctx->basic_blocks = ctx->basic_blocks->next; + frags = total_size / new_size; + ctx->stats[new_size].blocks++; + ctx->stats[new_size].freefrags += frags; + /* + * Set up a linked-list of blocks of size + * "new_size". + */ + curr = new; + next = curr + new_size; + for (i = 0; i < (frags - 1); i++) { + ((element *)curr)->next = (element *)next; + curr = next; + next += new_size; + } + /* + * curr is now pointing at the last block in the + * array. + */ + ((element *)curr)->next = NULL; + ctx->freelists[new_size] = new; + + return (ISC_TRUE); +} static inline void * -mem_getunlocked(isc_mem_t *ctx, size_t size) -{ +mem_getunlocked(isc_mem_t *ctx, size_t size) { size_t new_size = quantize(size); void *ret; if (size >= ctx->max_size || new_size >= ctx->max_size) { - /* memget() was called on something beyond our upper limit. */ + /* + * memget() was called on something beyond our upper limit. + */ if (ctx->quota != 0 && ctx->total + size > ctx->quota) { ret = NULL; goto done; @@ -438,6 +622,7 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) ret = (ctx->memalloc)(ctx->arg, size); if (ret != NULL) { ctx->total += size; + ctx->inuse += size; ctx->stats[ctx->max_size].gets++; ctx->stats[ctx->max_size].totalgets++; /* @@ -455,39 +640,12 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) * of memory and then break it up into "new_size"-sized blocks, adding * them to the free list. */ - if (ctx->freelists[new_size] == NULL) { - int i, frags; - size_t total_size; - void *new; - unsigned char *curr, *next; - - if (ctx->basic_blocks == NULL) { - more_basic_blocks(ctx); - if (ctx->basic_blocks == NULL) { - ret = NULL; - goto done; - } - } - total_size = ctx->mem_target; - new = ctx->basic_blocks; - ctx->basic_blocks = ctx->basic_blocks->next; - frags = total_size / new_size; - ctx->stats[new_size].blocks++; - ctx->stats[new_size].freefrags += frags; - /* Set up a linked-list of blocks of size "new_size". */ - curr = new; - next = curr + new_size; - for (i = 0; i < (frags - 1); i++) { - ((element *)curr)->next = (element *)next; - curr = next; - next += new_size; - } - /* curr is now pointing at the last block in the array. */ - ((element *)curr)->next = NULL; - ctx->freelists[new_size] = new; - } + if (ctx->freelists[new_size] == NULL && !more_frags(ctx, new_size)) + return (NULL); - /* The free list uses the "rounded-up" size "new_size": */ + /* + * The free list uses the "rounded-up" size "new_size". + */ ret = ctx->freelists[new_size]; ctx->freelists[new_size] = ctx->freelists[new_size]->next; @@ -500,6 +658,7 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) ctx->stats[size].gets++; ctx->stats[size].totalgets++; ctx->stats[new_size].freefrags--; + ctx->inuse += new_size; done: @@ -512,8 +671,7 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) } void -__isc_mem_put(isc_mem_t *ctx, void *mem, size_t size) -{ +isc__mem_put(isc_mem_t *ctx, void *mem, size_t size) { REQUIRE(VALID_CONTEXT(ctx)); LOCK(&ctx->lock); @@ -522,12 +680,13 @@ __isc_mem_put(isc_mem_t *ctx, void *mem, size_t size) } static inline void -mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) -{ +mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) { size_t new_size = quantize(size); if (size == ctx->max_size || new_size >= ctx->max_size) { - /* memput() called on something beyond our upper limit */ + /* + * memput() called on something beyond our upper limit. + */ #if ISC_MEM_FILL memset(mem, 0xde, size); /* Mnemonic for "dead". */ #endif @@ -535,6 +694,7 @@ mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) INSIST(ctx->stats[ctx->max_size].gets != 0); ctx->stats[ctx->max_size].gets--; INSIST(size <= ctx->total); + ctx->inuse -= size; ctx->total -= size; return; } @@ -546,7 +706,9 @@ mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) memset(mem, 0xde, new_size); /* Mnemonic for "dead". */ #endif - /* The free list uses the "rounded-up" size "new_size": */ + /* + * The free list uses the "rounded-up" size "new_size". + */ ((element *)mem)->next = ctx->freelists[new_size]; ctx->freelists[new_size] = (element *)mem; @@ -559,25 +721,50 @@ mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) INSIST(ctx->stats[size].gets != 0); ctx->stats[size].gets--; ctx->stats[new_size].freefrags++; + ctx->inuse -= new_size; } void * -__isc_mem_getdebug(isc_mem_t *ctx, size_t size, const char *file, int line) { +isc__mem_getdebug(isc_mem_t *ctx, size_t size, const char *file, int line) { void *ptr; - ptr = __isc_mem_get(ctx, size); + ptr = isc__mem_get(ctx, size); fprintf(stderr, "%s:%d: mem_get(%p, %lu) -> %p\n", file, line, ctx, (unsigned long)size, ptr); return (ptr); } void -__isc_mem_putdebug(isc_mem_t *ctx, void *ptr, size_t size, const char *file, +isc__mem_putdebug(isc_mem_t *ctx, void *ptr, size_t size, const char *file, int line) { fprintf(stderr, "%s:%d: mem_put(%p, %p, %lu)\n", file, line, ctx, ptr, (unsigned long)size); - __isc_mem_put(ctx, ptr, size); + isc__mem_put(ctx, ptr, size); +} + +isc_result_t +isc_mem_preallocate(isc_mem_t *ctx) { + size_t i; + isc_result_t result = ISC_R_SUCCESS; + void *ptr; + + REQUIRE(VALID_CONTEXT(ctx)); + + LOCK(&ctx->lock); + + for (i = 0; i < ctx->max_size; i += ALIGNMENT_SIZE) { + ptr = mem_getunlocked(ctx, i); + if (ptr == NULL) { + result = ISC_R_NOMEMORY; + break; + } + mem_putunlocked(ctx, ptr, i); + } + + UNLOCK(&ctx->lock); + + return (result); } /* @@ -656,11 +843,11 @@ isc_mem_valid(isc_mem_t *ctx, void *ptr) { */ void * -__isc_mem_allocate(isc_mem_t *ctx, size_t size) { +isc__mem_allocate(isc_mem_t *ctx, size_t size) { size_info *si; size += ALIGNMENT_SIZE; - si = __isc_mem_get(ctx, size); + si = isc__mem_get(ctx, size); if (si == NULL) return (NULL); si->u.size = size; @@ -668,11 +855,11 @@ __isc_mem_allocate(isc_mem_t *ctx, size_t size) { } void * -__isc_mem_allocatedebug(isc_mem_t *ctx, size_t size, const char *file, +isc__mem_allocatedebug(isc_mem_t *ctx, size_t size, const char *file, int line) { size_info *si; - si = __isc_mem_allocate(ctx, size); + si = isc__mem_allocate(ctx, size); if (si == NULL) return (NULL); fprintf(stderr, "%s:%d: mem_get(%p, %lu) -> %p\n", file, line, @@ -681,21 +868,21 @@ __isc_mem_allocatedebug(isc_mem_t *ctx, size_t size, const char *file, } void -__isc_mem_free(isc_mem_t *ctx, void *ptr) { +isc__mem_free(isc_mem_t *ctx, void *ptr) { size_info *si; si = &(((size_info *)ptr)[-1]); - __isc_mem_put(ctx, si, si->u.size); + isc__mem_put(ctx, si, si->u.size); } void -__isc_mem_freedebug(isc_mem_t *ctx, void *ptr, const char *file, int line) { +isc__mem_freedebug(isc_mem_t *ctx, void *ptr, const char *file, int line) { size_info *si; si = &(((size_info *)ptr)[-1]); fprintf(stderr, "%s:%d: mem_put(%p, %p, %lu)\n", file, line, ctx, ptr, (unsigned long)si->u.size); - __isc_mem_put(ctx, si, si->u.size); + isc__mem_put(ctx, si, si->u.size); } /* @@ -703,12 +890,12 @@ __isc_mem_freedebug(isc_mem_t *ctx, void *ptr, const char *file, int line) { */ char * -__isc_mem_strdup(isc_mem_t *mctx, const char *s) { +isc__mem_strdup(isc_mem_t *mctx, const char *s) { size_t len; char *ns; len = strlen(s); - ns = __isc_mem_allocate(mctx, len + 1); + ns = isc__mem_allocate(mctx, len + 1); if (ns == NULL) return (NULL); strncpy(ns, s, len + 1); @@ -717,27 +904,36 @@ __isc_mem_strdup(isc_mem_t *mctx, const char *s) { } char * -__isc_mem_strdupdebug(isc_mem_t *mctx, const char *s, const char *file, +isc__mem_strdupdebug(isc_mem_t *mctx, const char *s, const char *file, int line) { char *ptr; size_info *si; - ptr = __isc_mem_strdup(mctx, s); + ptr = isc__mem_strdup(mctx, s); si = &(((size_info *)ptr)[-1]); fprintf(stderr, "%s:%d: mem_get(%p, %lu) -> %p\n", file, line, mctx, (unsigned long)si->u.size, ptr); return (ptr); } -isc_boolean_t -isc_mem_destroy_check(isc_mem_t *mctx, isc_boolean_t flag) { - isc_boolean_t oldval; +void +isc_mem_setdestroycheck(isc_mem_t *ctx, isc_boolean_t flag) { + REQUIRE(VALID_CONTEXT(ctx)); + LOCK(&ctx->lock); + + ctx->checkfree = flag; + + UNLOCK(&ctx->lock); +} + +void +isc_mem_setsplit(isc_mem_t *ctx, isc_boolean_t flag) { + REQUIRE(VALID_CONTEXT(ctx)); + LOCK(&ctx->lock); - INSIST(mctx != NULL); + ctx->trysplit = flag; - oldval = mctx->checkfree; - mctx->checkfree = flag; - return (oldval); + UNLOCK(&ctx->lock); } @@ -769,6 +965,20 @@ isc_mem_getquota(isc_mem_t *ctx) { return (quota); } +size_t +isc_mem_inuse(isc_mem_t *ctx) { + size_t inuse; + + REQUIRE(VALID_CONTEXT(ctx)); + LOCK(&ctx->lock); + + inuse = ctx->inuse; + + UNLOCK(&ctx->lock); + + return (inuse); +} + #ifdef ISC_MEMCLUSTER_LEGACY /* @@ -779,7 +989,9 @@ static isc_mem_t *default_context = NULL; int meminit(size_t init_max_size, size_t target_size) { - /* need default_context lock here */ + /* + * Need default_context lock here. + */ if (default_context != NULL) return (-1); return (isc_mem_create(init_max_size, target_size, &default_context)); @@ -787,55 +999,65 @@ meminit(size_t init_max_size, size_t target_size) { isc_mem_t * mem_default_context(void) { - /* need default_context lock here */ + /* + * Need default_context lock here. + */ if (default_context == NULL && meminit(0, 0) == -1) return (NULL); return (default_context); } void * -__memget(size_t size) { - /* need default_context lock here */ +isc__legacy_memget(size_t size) { + /* + * Need default_context lock here. + */ if (default_context == NULL && meminit(0, 0) == -1) return (NULL); - return (__mem_get(default_context, size)); + return (isc__mem_get(default_context, size)); } void -__memput(void *mem, size_t size) { - /* need default_context lock here */ +isc__legacy_memput(void *mem, size_t size) { + /* + * Need default_context lock here. + */ REQUIRE(default_context != NULL); - __mem_put(default_context, mem, size); + isc__mem_put(default_context, mem, size); } void * -__memget_debug(size_t size, const char *file, int line) { +isc__legacy_memget_debug(size_t size, const char *file, int line) { void *ptr; - ptr = __memget(size); + ptr = isc__legacy_memget(size); fprintf(stderr, "%s:%d: memget(%lu) -> %p\n", file, line, (unsigned long)size, ptr); return (ptr); } void -__memput_debug(void *ptr, size_t size, const char *file, int line) { +isc__legacy_memput_debug(void *ptr, size_t size, const char *file, int line) { fprintf(stderr, "%s:%d: memput(%p, %lu)\n", file, line, ptr, (unsigned long)size); - __memput(ptr, size); + isc__legacy_memput(ptr, size); } int memvalid(void *ptr) { - /* need default_context lock here */ + /* + * Need default_context lock here. + */ REQUIRE(default_context != NULL); - return (mem_valid(default_context, ptr)); + return (isc_mem_valid(default_context, ptr)); } void memstats(FILE *out) { - /* need default_context lock here */ + /* + * Need default_context lock here. + */ REQUIRE(default_context != NULL); - mem_stats(default_context, out); + isc_mem_stats(default_context, out); } #endif /* ISC_MEMCLUSTER_LEGACY */ @@ -852,8 +1074,7 @@ memstats(FILE *out) { * will be returned to the mctx. */ static void -mempool_release(isc_mempool_t *mpctx, unsigned int n) -{ +mempool_release(isc_mempool_t *mpctx, unsigned int n) { isc_mem_t *mctx; element *item; element *next; @@ -892,8 +1113,7 @@ mempool_release(isc_mempool_t *mpctx, unsigned int n) * context must be locked, and the pool if needed. */ static void -mempool_releaseall(isc_mempool_t *mpctx) -{ +mempool_releaseall(isc_mempool_t *mpctx) { isc_mem_t *mctx; element *item; element *next; @@ -916,8 +1136,7 @@ mempool_releaseall(isc_mempool_t *mpctx) } isc_result_t -isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) -{ +isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) { isc_mempool_t *mpctx; REQUIRE(VALID_CONTEXT(mctx)); @@ -961,8 +1180,7 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) } void -isc_mempool_setname(isc_mempool_t *mpctx, char *name) -{ +isc_mempool_setname(isc_mempool_t *mpctx, char *name) { REQUIRE(name != NULL); #if ISC_MEMPOOL_NAMES @@ -981,8 +1199,7 @@ isc_mempool_setname(isc_mempool_t *mpctx, char *name) } void -isc_mempool_destroy(isc_mempool_t **mpctxp) -{ +isc_mempool_destroy(isc_mempool_t **mpctxp) { isc_mempool_t *mpctx; isc_mem_t *mctx; isc_mutex_t *lock; @@ -1024,8 +1241,7 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) } void -isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock) -{ +isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock) { REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(mpctx->lock == NULL); REQUIRE(lock != NULL); @@ -1034,8 +1250,7 @@ isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock) } void * -__isc_mempool_get(isc_mempool_t *mpctx) -{ +isc__mempool_get(isc_mempool_t *mpctx) { element *item; isc_mem_t *mctx; unsigned int i; @@ -1103,8 +1318,7 @@ __isc_mempool_get(isc_mempool_t *mpctx) } void -__isc_mempool_put(isc_mempool_t *mpctx, void *mem) -{ +isc__mempool_put(isc_mempool_t *mpctx, void *mem) { isc_mem_t *mctx; element *item; @@ -1123,7 +1337,7 @@ __isc_mempool_put(isc_mempool_t *mpctx, void *mem) * If our free list is full, return this to the mctx directly. */ if (mpctx->freecount >= mpctx->freemax) { - __isc_mem_put(mctx, mem, mpctx->size); + isc__mem_put(mctx, mem, mpctx->size); if (mpctx->lock != NULL) UNLOCK(mpctx->lock); return; @@ -1142,12 +1356,10 @@ __isc_mempool_put(isc_mempool_t *mpctx, void *mem) } void * -__isc_mempool_getdebug(isc_mempool_t *mpctx, - const char *file, int line) -{ +isc__mempool_getdebug(isc_mempool_t *mpctx, const char *file, int line) { void *ptr; - ptr = __isc_mempool_get(mpctx); + ptr = isc__mempool_get(mpctx); fprintf(stderr, "%s:%d: mempool_get(%p) -> %p\n", file, line, mpctx, ptr); @@ -1155,12 +1367,12 @@ __isc_mempool_getdebug(isc_mempool_t *mpctx, } void -__isc_mempool_putdebug(isc_mempool_t *mpctx, void *ptr, - const char *file, int line) +isc__mempool_putdebug(isc_mempool_t *mpctx, void *ptr, const char *file, + int line) { fprintf(stderr, "%s:%d: mempool_put(%p, %p)\n", file, line, mpctx, ptr); - __isc_mempool_put(mpctx, ptr); + isc__mempool_put(mpctx, ptr); } /* @@ -1168,8 +1380,7 @@ __isc_mempool_putdebug(isc_mempool_t *mpctx, void *ptr, */ void -isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) -{ +isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) { REQUIRE(VALID_MEMPOOL(mpctx)); if (mpctx->lock != NULL) @@ -1182,8 +1393,7 @@ isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) } unsigned int -isc_mempool_getfreemax(isc_mempool_t *mpctx) -{ +isc_mempool_getfreemax(isc_mempool_t *mpctx) { unsigned int freemax; REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1200,8 +1410,7 @@ isc_mempool_getfreemax(isc_mempool_t *mpctx) } unsigned int -isc_mempool_getfreecount(isc_mempool_t *mpctx) -{ +isc_mempool_getfreecount(isc_mempool_t *mpctx) { unsigned int freecount; REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1218,8 +1427,7 @@ isc_mempool_getfreecount(isc_mempool_t *mpctx) } void -isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit) -{ +isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit) { REQUIRE(limit > 0); REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1234,8 +1442,7 @@ isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit) } unsigned int -isc_mempool_getmaxalloc(isc_mempool_t *mpctx) -{ +isc_mempool_getmaxalloc(isc_mempool_t *mpctx) { unsigned int maxalloc; REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1252,8 +1459,7 @@ isc_mempool_getmaxalloc(isc_mempool_t *mpctx) } unsigned int -isc_mempool_getallocated(isc_mempool_t *mpctx) -{ +isc_mempool_getallocated(isc_mempool_t *mpctx) { unsigned int allocated; REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1270,8 +1476,7 @@ isc_mempool_getallocated(isc_mempool_t *mpctx) } void -isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) -{ +isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) { REQUIRE(limit > 0); REQUIRE(VALID_MEMPOOL(mpctx)); @@ -1285,8 +1490,7 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) } unsigned int -isc_mempool_getfillcount(isc_mempool_t *mpctx) -{ +isc_mempool_getfillcount(isc_mempool_t *mpctx) { unsigned int fillcount; REQUIRE(VALID_MEMPOOL(mpctx)); |