aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/malloc.c
diff options
context:
space:
mode:
authorDan Cross <cross@gajendra.net>2020-01-16 16:54:19 +0000
committerDan Cross <cross@gajendra.net>2020-01-16 16:54:19 +0000
commit7bf2db4c2ae30c0f7b320e57060715bf6279e98a (patch)
tree4b1d40a34ec3dbd9c3d936e04b6ed9f3c92ef589 /src/lib9/malloc.c
parent3ef80ba5f5c29a8367d32353a9620ec4cf9cb880 (diff)
downloadplan9port-7bf2db4c2ae30c0f7b320e57060715bf6279e98a.tar.gz
plan9port-7bf2db4c2ae30c0f7b320e57060715bf6279e98a.tar.bz2
plan9port-7bf2db4c2ae30c0f7b320e57060715bf6279e98a.zip
malloc: remove locking
The issue manifests in fork: POSIX fork mandates that a fork'd process is created with a single thread. If a multithreaded program forks, and some thread was in malloc() when the fork() happened, then in the child the lock will be held but there will be no thread to release it. We assume the system malloc() must already know how to deal with this and is thread-safe, but it won't know about our custom spinlock. Judging that this is no longer necessary (the lock code was added 15 years ago) we remove it. Signed-off-by: Dan Cross <cross@gajendra.net>
Diffstat (limited to 'src/lib9/malloc.c')
-rw-r--r--src/lib9/malloc.c25
1 files changed, 3 insertions, 22 deletions
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 <libc.h>
-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);
}