diff options
author | rsc <devnull@localhost> | 2005-07-14 00:06:43 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-07-14 00:06:43 +0000 |
commit | 8be32ce2cb17950569b94273cee6099289c4d022 (patch) | |
tree | f29119e67355d2c1ae6eae03222ea757a6facfa1 | |
parent | 750819026920751b81833cb60270ad7047e75cdc (diff) | |
download | plan9port-8be32ce2cb17950569b94273cee6099289c4d022.tar.gz plan9port-8be32ce2cb17950569b94273cee6099289c4d022.tar.bz2 plan9port-8be32ce2cb17950569b94273cee6099289c4d022.zip |
cannot trust system libraries to lock properly. sigh.
-rw-r--r-- | src/lib9/malloc.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/lib9/malloc.c b/src/lib9/malloc.c index a32178b3..7b6b59dc 100644 --- a/src/lib9/malloc.c +++ b/src/lib9/malloc.c @@ -7,12 +7,19 @@ #define NOPLAN9DEFINES #include <libc.h> +static Lock malloclock; + void* p9malloc(ulong n) { + void *v; + if(n == 0) n++; - return malloc(n); + lock(&malloclock); + v = malloc(n); + unlock(&malloclock); + return v; } void @@ -20,20 +27,30 @@ 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; - return calloc(a*b, 1); + lock(&malloclock); + v = calloc(a*b, 1); + unlock(&malloclock); + return v; } void* p9realloc(void *v, ulong n) { - return realloc(v, n); + lock(&malloclock); + v = realloc(v, n); + unlock(&malloclock); + return v; } |