summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-03-28 18:40:44 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-03-28 18:40:44 +0000
commit11343788cbaaede18e3146b5219d2fbdaeaf516e (patch)
treeef2be09ece0508b3408a222a86980d39e20bcd42 /malloc.c
parenta4f68e9b64464684b732bc17fd65ed4a1aa4708c (diff)
downloadperl-11343788cbaaede18e3146b5219d2fbdaeaf516e.tar.gz
Initial 3-way merge from (5.001m, thr1m, 5.003) plus fixups.
p4raw-id: //depot/thrperl@4
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index 581cbd3755..7c23adb92b 100644
--- a/malloc.c
+++ b/malloc.c
@@ -126,6 +126,7 @@ malloc(nbytes)
#endif
#endif /* safemalloc */
+ MUTEX_LOCK(&malloc_mutex);
/*
* Convert amount of memory requested into
* closest block size stored in hash buckets
@@ -145,6 +146,7 @@ malloc(nbytes)
if (nextf[bucket] == NULL)
morecore(bucket);
if ((p = (union overhead *)nextf[bucket]) == NULL) {
+ MUTEX_UNLOCK(&malloc_mutex);
#ifdef safemalloc
if (!nomemok) {
fputs("Out of memory!\n", stderr);
@@ -182,6 +184,7 @@ malloc(nbytes)
p->ov_rmagic = RMAGIC;
*((u_int *)((caddr_t)p + nbytes - RSLOP)) = RMAGIC;
#endif
+ MUTEX_UNLOCK(&malloc_mutex);
return ((Malloc_t)(p + 1));
}
@@ -281,6 +284,7 @@ free(mp)
return; /* sanity */
}
#endif
+ MUTEX_LOCK(&malloc_mutex);
#ifdef RCHECK
ASSERT(op->ov_rmagic == RMAGIC);
if (op->ov_index <= 13)
@@ -294,6 +298,7 @@ free(mp)
#ifdef DEBUGGING_MSTATS
nmalloc[size]--;
#endif
+ MUTEX_UNLOCK(&malloc_mutex);
}
/*
@@ -340,6 +345,7 @@ realloc(mp, nbytes)
#endif
#endif /* safemalloc */
+ MUTEX_LOCK(&malloc_mutex);
op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
if (op->ov_magic == MAGIC) {
was_alloced++;
@@ -383,8 +389,10 @@ realloc(mp, nbytes)
}
#endif
res = cp;
+ MUTEX_UNLOCK(&malloc_mutex);
}
else {
+ MUTEX_UNLOCK(&malloc_mutex);
if ((res = (char*)malloc(nbytes)) == NULL)
return (NULL);
if (cp != res) /* common optimization */