diff --git a/src/cmd/9term/malloc.c b/src/cmd/9term/malloc.c index 9132235b..7b590bc4 100644 --- a/src/cmd/9term/malloc.c +++ b/src/cmd/9term/malloc.c @@ -7,8 +7,6 @@ #define NOPLAN9DEFINES #include -static Lock malloclock; - void* p9malloc(ulong n) { @@ -16,9 +14,7 @@ p9malloc(ulong n) if(n == 0) n++; - lock(&malloclock); v = malloc(n); - unlock(&malloclock); print("p9malloc %lud => %p; pc %lux\n", n, v, getcallerpc(&n)); return v; } @@ -28,10 +24,8 @@ p9free(void *v) { if(v == nil) return; - lock(&malloclock); print("p9free %p; pc %lux\n", v, getcallerpc(&v)); free(v); - unlock(&malloclock); } void* @@ -42,9 +36,7 @@ p9calloc(ulong a, ulong b) if(a*b == 0) a = b = 1; - lock(&malloclock); v = calloc(a*b, 1); - unlock(&malloclock); print("p9calloc %lud %lud => %p; pc %lux\n", a, b, v, getcallerpc(&a)); return v; } @@ -54,9 +46,7 @@ p9realloc(void *v, ulong n) { void *vv; - lock(&malloclock); vv = realloc(v, n); - unlock(&malloclock); print("p9realloc %p %lud => %p; pc %lux\n", v, n, vv, getcallerpc(&v)); return vv; } diff --git a/src/lib9/debugmalloc.c b/src/lib9/debugmalloc.c index 51a2c61f..744af835 100644 --- a/src/lib9/debugmalloc.c +++ b/src/lib9/debugmalloc.c @@ -6,7 +6,6 @@ * The Unix libc routines cannot be trusted to do their own locking. * Sad but apparently true. */ -static Lock malloclock; static int mallocpid; /* @@ -112,11 +111,9 @@ p9malloc(ulong n) if(n == 0) n++; /*fprint(2, "%s %d malloc\n", argv0, getpid()); */ - lock(&malloclock); mallocpid = getpid(); v = malloc(n+Overhead); v = mark(v, getcallerpc(&n), n, MallocMagic); - unlock(&malloclock); /*fprint(2, "%s %d donemalloc\n", argv0, getpid()); */ return v; } @@ -128,11 +125,9 @@ p9free(void *v) return; /*fprint(2, "%s %d free\n", argv0, getpid()); */ - lock(&malloclock); mallocpid = getpid(); v = mark(v, getcallerpc(&v), 0, FreeMagic); free(v); - unlock(&malloclock); /*fprint(2, "%s %d donefree\n", argv0, getpid()); */ } @@ -142,11 +137,9 @@ p9calloc(ulong a, ulong b) void *v; /*fprint(2, "%s %d calloc\n", argv0, getpid()); */ - lock(&malloclock); mallocpid = getpid(); v = calloc(a*b+Overhead, 1); v = mark(v, getcallerpc(&a), a*b, CallocMagic); - unlock(&malloclock); /*fprint(2, "%s %d donecalloc\n", argv0, getpid()); */ return v; } @@ -155,12 +148,10 @@ void* p9realloc(void *v, ulong n) { /*fprint(2, "%s %d realloc\n", argv0, getpid()); */ - lock(&malloclock); mallocpid = getpid(); v = mark(v, getcallerpc(&v), 0, CheckMagic); v = realloc(v, n+Overhead); v = mark(v, getcallerpc(&v), n, ReallocMagic); - unlock(&malloclock); /*fprint(2, "%s %d donerealloc\n", argv0, getpid()); */ return v; } diff --git a/src/lib9/malloc.c b/src/lib9/malloc.c index 33593aa2..695ff8bc 100644 --- a/src/lib9/malloc.c +++ b/src/lib9/malloc.c @@ -7,50 +7,31 @@ #define NOPLAN9DEFINES #include -static Lock malloclock; void* p9malloc(ulong n) { - void *v; - if(n == 0) n++; - lock(&malloclock); - v = malloc(n); - unlock(&malloclock); - return v; + return malloc(n); } void p9free(void *v) { - if(v == nil) - return; - lock(&malloclock); free(v); - unlock(&malloclock); } void* p9calloc(ulong a, ulong b) { - void *v; - if(a*b == 0) a = b = 1; - - lock(&malloclock); - v = calloc(a*b, 1); - unlock(&malloclock); - return v; + return calloc(a, b); } void* p9realloc(void *v, ulong n) { - lock(&malloclock); - v = realloc(v, n); - unlock(&malloclock); - return v; + return realloc(v, n); }