Commit 4cafb28a authored by Bob Halley's avatar Bob Halley
Browse files

change memctx to mem; cleanups; fix debug trace problem

parent b2df2daf
......@@ -15,8 +15,8 @@
* SOFTWARE.
*/
#ifndef ISC_MEMCLUSTER_H
#define ISC_MEMCLUSTER_H 1
#ifndef ISC_MEM_H
#define ISC_MEM_H 1
#include <stdio.h>
#include <stddef.h>
......@@ -24,31 +24,28 @@
#include <isc/boolean.h>
#include <isc/result.h>
typedef struct isc_memctx isc_memctx_t;
typedef struct isc_mem isc_mem_t;
#ifdef ISC_MEMCLUSTER_DEBUG
#define isc_mem_get(c, s) isc_mem_getdebug(c, s, __FILE__, \
__LINE__)
#define isc_mem_put(c, p, s) isc_mem_putdebug(c, p, s, __FILE__, \
__LINE__)
#ifdef ISC_MEM_DEBUG
#define isc_mem_get(c, s) __isc_mem_getdebug(c, s, __FILE__, __LINE__)
#define isc_mem_put(c, p, s) __isc_mem_putdebug(c, p, s, __FILE__, __LINE__)
#else
#define isc_mem_get isc_mem_get
#define isc_mem_put isc_mem_put
#endif /* ISC_MEMCLUSTER_DEBUG */
#define isc_mem_get __isc_mem_get
#define isc_mem_put __isc_mem_put
#endif /* ISC_MEM_DEBUG */
isc_result_t isc_memctx_create(size_t, size_t,
isc_memctx_t **);
void isc_memctx_destroy(isc_memctx_t **);
void * isc_mem_get(isc_memctx_t *, size_t);
void isc_mem_put(isc_memctx_t *, void *, size_t);
void * isc_mem_getdebug(isc_memctx_t *, size_t,
isc_result_t isc_mem_create(size_t, size_t, isc_mem_t **);
void isc_mem_destroy(isc_mem_t **);
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,
const char *, int);
void isc_mem_putdebug(isc_memctx_t *, void *,
size_t, const char *, int);
isc_boolean_t isc_mem_valid(isc_memctx_t *, void *);
void isc_mem_stats(isc_memctx_t *, FILE *);
void * isc_mem_allocate(isc_memctx_t *, size_t);
void isc_mem_free(isc_memctx_t *, void *);
void __isc_mem_putdebug(isc_mem_t *, void *,
size_t, const char *, int);
void isc_mem_stats(isc_mem_t *, FILE *);
isc_boolean_t isc_mem_valid(isc_mem_t *, void *);
void * isc_mem_allocate(isc_mem_t *, size_t);
void isc_mem_free(isc_mem_t *, void *);
#ifdef ISC_MEMCLUSTER_LEGACY
......@@ -69,7 +66,7 @@ void isc_mem_free(isc_memctx_t *, void *);
#define memstats __memstats
int meminit(size_t, size_t);
isc_memctx_t * mem_default_context(void);
isc_mem_t * mem_default_context(void);
void * __memget(size_t);
void __memput(void *, size_t);
void * __memget_debug(size_t, const char *, int);
......@@ -80,4 +77,4 @@ void memstats(FILE *);
#endif /* ISC_MEMCLUSTER_LEGACY */
#endif /* MEMCLUSTER_H */
#endif /* MEM_H */
......@@ -56,11 +56,10 @@ struct stats {
unsigned long freefrags;
};
#define MEM_MAGIC 0x4D656d43U /* MemC. */
#define VALID_CONTEXT(c) ((c) != NULL && \
(c)->magic == MEM_MAGIC)
#define MEM_MAGIC 0x4D656d43U /* MemC. */
#define VALID_CONTEXT(c) ((c) != NULL && (c)->magic == MEM_MAGIC)
struct isc_memctx {
struct isc_mem {
unsigned int magic;
isc_mutex_t lock;
size_t max_size;
......@@ -112,10 +111,10 @@ quantize(size_t size) {
/* Public. */
isc_result_t
isc_memctx_create(size_t init_max_size, size_t target_size,
isc_memctx_t **ctxp)
isc_mem_create(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp)
{
isc_memctx_t *ctx;
isc_mem_t *ctx;
REQUIRE(ctxp != NULL && *ctxp == NULL);
......@@ -162,9 +161,9 @@ isc_memctx_create(size_t init_max_size, size_t target_size,
}
void
isc_memctx_destroy(isc_memctx_t **ctxp) {
isc_mem_destroy(isc_mem_t **ctxp) {
unsigned int i;
isc_memctx_t *ctx;
isc_mem_t *ctx;
REQUIRE(ctxp != NULL);
ctx = *ctxp;
......@@ -186,8 +185,10 @@ isc_memctx_destroy(isc_memctx_t **ctxp) {
*ctxp = NULL;
}
static void
more_basic_blocks(isc_memctx_t *ctx) {
more_basic_blocks(isc_mem_t *ctx) {
void *new;
unsigned char *curr, *next;
unsigned char *first, *last;
......@@ -240,7 +241,7 @@ more_basic_blocks(isc_memctx_t *ctx) {
}
void *
isc_mem_get(isc_memctx_t *ctx, size_t size) {
__isc_mem_get(isc_mem_t *ctx, size_t size) {
size_t new_size = quantize(size);
void *ret;
......@@ -315,12 +316,8 @@ isc_mem_get(isc_memctx_t *ctx, size_t size) {
return (ret);
}
/*
* This is a call from an external caller,
* so we want to count this as a user "put".
*/
void
isc_mem_put(isc_memctx_t *ctx, void *mem, size_t size) {
__isc_mem_put(isc_mem_t *ctx, void *mem, size_t size) {
size_t new_size = quantize(size);
REQUIRE(size > 0);
......@@ -354,29 +351,29 @@ isc_mem_put(isc_memctx_t *ctx, void *mem, size_t size) {
}
void *
isc_mem_getdebug(isc_memctx_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_memctx_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);
}
/*
* Print the stats[] on the stream "out" with suitable formatting.
*/
void
isc_mem_stats(isc_memctx_t *ctx, FILE *out) {
isc_mem_stats(isc_mem_t *ctx, FILE *out) {
size_t i;
REQUIRE(VALID_CONTEXT(ctx));
......@@ -402,7 +399,7 @@ isc_mem_stats(isc_memctx_t *ctx, FILE *out) {
}
isc_boolean_t
isc_mem_valid(isc_memctx_t *ctx, void *ptr) {
isc_mem_valid(isc_mem_t *ctx, void *ptr) {
unsigned char *cp = ptr;
isc_boolean_t result = ISC_FALSE;
......@@ -422,7 +419,7 @@ isc_mem_valid(isc_memctx_t *ctx, void *ptr) {
*/
void *
isc_mem_allocate(isc_memctx_t *ctx, size_t size) {
isc_mem_allocate(isc_mem_t *ctx, size_t size) {
size_info *si;
size += ALIGNMENT_SIZE;
......@@ -434,7 +431,7 @@ isc_mem_allocate(isc_memctx_t *ctx, size_t size) {
}
void
isc_mem_free(isc_memctx_t *ctx, void *ptr) {
isc_mem_free(isc_mem_t *ctx, void *ptr) {
size_info *si;
si = &(((size_info *)ptr)[-1]);
......@@ -447,7 +444,7 @@ isc_mem_free(isc_memctx_t *ctx, void *ptr) {
* Public Legacy.
*/
static isc_memctx_t *default_context = NULL;
static isc_mem_t *default_context = NULL;
int
meminit(size_t init_max_size, size_t target_size) {
......@@ -457,7 +454,7 @@ meminit(size_t init_max_size, size_t target_size) {
return (isc_mem_create(init_max_size, target_size, &default_context));
}
isc_memctx_t
isc_mem_t *
mem_default_context(void) {
/* need default_context lock here */
if (default_context == NULL && meminit(0, 0) == -1)
......
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