#include "mem_p.h"
-#define MCTXLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)
-#define MCTXUNLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)
+#define MCTXLOCK(m) LOCK(&m->lock)
+#define MCTXUNLOCK(m) UNLOCK(&m->lock)
#ifndef ISC_MEM_DEBUGGING
#define ISC_MEM_DEBUGGING 0
ctx = (default_memalloc)(sizeof(*ctx));
- if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
- isc_mutex_init(&ctx->lock);
- }
+ isc_mutex_init(&ctx->lock);
ctx->max_size = DEF_MAX_SIZE;
ctx->flags = flags;
}
}
- if ((ctx->flags & ISC_MEMFLAG_NOLOCK) == 0)
- isc_mutex_destroy(&ctx->lock);
+ isc_mutex_destroy(&ctx->lock);
+
ctx->malloced -= sizeof(*ctx);
if (ctx->checkfree)
INSIST(ctx->malloced == 0);
goto destroy;
}
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
mem_putstats(ctx, ptr, size);
mem_put(ctx, ptr, size);
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
destroy:
if (isc_refcount_decrement(&ctx->references) == 1) {
return (isc__mem_allocate(ctx0, size FLARG_PASS));
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
ptr = mem_getunlocked(ctx, size);
} else {
ptr = mem_get(ctx, size);
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
if (ptr != NULL)
mem_getstats(ctx, size);
}
fprintf(stderr, "maxinuse = %lu\n",
(unsigned long)ctx->inuse);
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
if (call_water && (ctx->water != NULL))
(ctx->water)(ctx->water_arg, ISC_MEM_HIWATER);
return;
}
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
call_water = true;
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
if (call_water && (ctx->water != NULL))
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
if (flag == ISC_MEM_LOWATER)
ctx->hi_called = false;
else if (flag == ISC_MEM_HIWATER)
ctx->hi_called = true;
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
}
#if ISC_MEM_TRACKLINES
const isc__mempool_t *pool;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
for (i = 0; i <= ctx->max_size; i++) {
s = &ctx->stats[i];
print_active(ctx, out);
#endif
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
}
/*
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
si = mem_allocateunlocked((isc_mem_t *)ctx, size);
if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0)) {
mem_getstats(ctx, si[-1].u.size);
fprintf(stderr, "maxinuse = %lu\n",
(unsigned long)ctx->inuse);
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
if (call_water) {
(ctx->water)(ctx->water_arg, ISC_MEM_HIWATER);
size = si->u.size;
}
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
if (ctx->water != NULL)
call_water = true;
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
if (call_water)
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
isc__mem_t *ctx = (isc__mem_t *)ctx0;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
ctx->checkfree = flag;
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
}
size_t
size_t inuse;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
inuse = ctx->inuse;
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
return (inuse);
}
size_t maxinuse;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
maxinuse = ctx->maxinuse;
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
return (maxinuse);
}
size_t total;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
total = ctx->total;
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
return (total);
}
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(hiwater >= lowater);
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
oldwater = ctx->water;
oldwater_arg = ctx->water_arg;
if (water == NULL) {
ctx->hi_water = hiwater;
ctx->lo_water = lowater;
}
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
if (callwater && oldwater != NULL)
(oldwater)(oldwater_arg, ISC_MEM_LOWATER);
*mpctxp = (isc_mempool_t *)mpctx;
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
ISC_LIST_INITANDAPPEND(mctx->pools, mpctx, link);
mctx->poolcnt++;
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
return (ISC_R_SUCCESS);
}
/*
* Return any items on the free list
*/
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
while (mpctx->items != NULL) {
INSIST(mpctx->freecount > 0);
mpctx->freecount--;
mem_put(mctx, item, mpctx->size);
}
}
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
/*
* Remove our linked list entry from the memory context.
*/
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
ISC_LIST_UNLINK(mctx->pools, mpctx, link);
mctx->poolcnt--;
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
mpctx->common.impmagic = 0;
mpctx->common.magic = 0;
* We need to dip into the well. Lock the memory context
* here and fill up our free list.
*/
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
for (i = 0; i < mpctx->fillcount; i++) {
if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
item = mem_getunlocked(mctx, mpctx->size);
mpctx->items = item;
mpctx->freecount++;
}
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
}
/*
if (ISC_UNLIKELY(((isc_mem_debugging & TRACE_OR_RECORD) != 0) &&
item != NULL))
{
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
ADD_TRACE(mctx, item, mpctx->size, file, line);
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
}
#endif /* ISC_MEM_TRACKLINES */
#if ISC_MEM_TRACKLINES
if (ISC_UNLIKELY((isc_mem_debugging & TRACE_OR_RECORD) != 0)) {
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
DELETE_TRACE(mctx, mem, mpctx->size, file, line);
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
}
#endif /* ISC_MEM_TRACKLINES */
* If our free list is full, return this to the mctx directly.
*/
if (mpctx->freecount >= mpctx->freemax) {
- MCTXLOCK(mctx, &mctx->lock);
+ MCTXLOCK(mctx);
if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
mem_putunlocked(mctx, mem, mpctx->size);
} else {
mem_putstats(mctx, mem, mpctx->size);
mem_put(mctx, mem, mpctx->size);
}
- MCTXUNLOCK(mctx, &mctx->lock);
+ MCTXUNLOCK(mctx);
if (mpctx->lock != NULL)
UNLOCK(mpctx->lock);
return;
REQUIRE(VALID_CONTEXT(ctx));
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context"));
TRY0(xmlTextWriterEndElement(writer)); /* context */
error:
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
return (xmlrc);
}
REQUIRE(summary != NULL);
REQUIRE(array != NULL);
- MCTXLOCK(ctx, &ctx->lock);
+ MCTXLOCK(ctx);
summary->contextsize += sizeof(*ctx) +
(ctx->max_size + 1) * sizeof(struct stats) +
CHECKMEM(obj);
json_object_object_add(ctxobj, "lowater", obj);
- MCTXUNLOCK(ctx, &ctx->lock);
+ MCTXUNLOCK(ctx);
json_object_array_add(array, ctxobj);
return (ISC_R_SUCCESS);
}