mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
lock malloc ourselves
This commit is contained in:
parent
c9896e2edb
commit
7e0e6522e5
2 changed files with 54 additions and 7 deletions
|
@ -113,12 +113,9 @@ extern void* malloc(ulong);
|
||||||
*/
|
*/
|
||||||
extern void* p9malloc(ulong);
|
extern void* p9malloc(ulong);
|
||||||
extern void* mallocz(ulong, int);
|
extern void* mallocz(ulong, int);
|
||||||
/*
|
extern void p9free(void*);
|
||||||
extern void free(void*);
|
extern void* p9calloc(ulong, ulong);
|
||||||
extern ulong msize(void*);
|
extern void* p9realloc(void*, ulong);
|
||||||
extern void* calloc(ulong, ulong);
|
|
||||||
extern void* realloc(void*, ulong);
|
|
||||||
*/
|
|
||||||
extern void setmalloctag(void*, ulong);
|
extern void setmalloctag(void*, ulong);
|
||||||
extern void setrealloctag(void*, ulong);
|
extern void setrealloctag(void*, ulong);
|
||||||
extern ulong getmalloctag(void*);
|
extern ulong getmalloctag(void*);
|
||||||
|
@ -128,6 +125,9 @@ extern void* malloctopoolblock(void*);
|
||||||
*/
|
*/
|
||||||
#ifndef NOPLAN9DEFINES
|
#ifndef NOPLAN9DEFINES
|
||||||
#define malloc p9malloc
|
#define malloc p9malloc
|
||||||
|
#define realloc p9realloc
|
||||||
|
#define calloc p9calloc
|
||||||
|
#define free p9free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,10 +2,57 @@
|
||||||
#define NOPLAN9DEFINES
|
#define NOPLAN9DEFINES
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Unix libc routines cannot be trusted to do their own locking.
|
||||||
|
* Sad but apparently true.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static Lock malloclock;
|
||||||
|
|
||||||
void*
|
void*
|
||||||
p9malloc(ulong n)
|
p9malloc(ulong n)
|
||||||
{
|
{
|
||||||
|
void *v;
|
||||||
if(n == 0)
|
if(n == 0)
|
||||||
n++;
|
n++;
|
||||||
return malloc(n);
|
//fprint(2, "%s %d malloc\n", argv0, getpid());
|
||||||
|
lock(&malloclock);
|
||||||
|
v = malloc(n);
|
||||||
|
unlock(&malloclock);
|
||||||
|
//fprint(2, "%s %d donemalloc\n", argv0, getpid());
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p9free(void *v)
|
||||||
|
{
|
||||||
|
//fprint(2, "%s %d free\n", argv0, getpid());
|
||||||
|
lock(&malloclock);
|
||||||
|
free(v);
|
||||||
|
unlock(&malloclock);
|
||||||
|
//fprint(2, "%s %d donefree\n", argv0, getpid());
|
||||||
|
}
|
||||||
|
|
||||||
|
void*
|
||||||
|
p9calloc(ulong a, ulong b)
|
||||||
|
{
|
||||||
|
void *v;
|
||||||
|
|
||||||
|
//fprint(2, "%s %d calloc\n", argv0, getpid());
|
||||||
|
lock(&malloclock);
|
||||||
|
v = calloc(a, b);
|
||||||
|
unlock(&malloclock);
|
||||||
|
//fprint(2, "%s %d donecalloc\n", argv0, getpid());
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void*
|
||||||
|
p9realloc(void *v, ulong n)
|
||||||
|
{
|
||||||
|
//fprint(2, "%s %d realloc\n", argv0, getpid());
|
||||||
|
lock(&malloclock);
|
||||||
|
v = realloc(v, n);
|
||||||
|
unlock(&malloclock);
|
||||||
|
//fprint(2, "%s %d donerealloc\n", argv0, getpid());
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue