1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:14:40 -07:00

runtime: fix data race in Plan9 sysalloc

Add mutex to protect brk limit.
Add mstats.sys update.

R=rsc
CC=golang-dev
https://golang.org/cl/4762045
This commit is contained in:
Dmitriy Vyukov 2011-07-18 10:50:04 -04:00 committed by Russ Cox
parent e8689404a7
commit c1f035ba4c

View File

@ -8,6 +8,7 @@
extern byte end[]; extern byte end[];
static byte *bloc = { end }; static byte *bloc = { end };
static Lock memlock;
enum enum
{ {
@ -19,23 +20,31 @@ runtime·SysAlloc(uintptr nbytes)
{ {
uintptr bl; uintptr bl;
runtime·lock(&memlock);
mstats.sys += nbytes;
// Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
bl = ((uintptr)bloc + Round) & ~Round; bl = ((uintptr)bloc + Round) & ~Round;
if(runtime·brk_((void*)(bl + nbytes)) < 0) if(runtime·brk_((void*)(bl + nbytes)) < 0) {
runtime·unlock(&memlock);
return (void*)-1; return (void*)-1;
}
bloc = (byte*)bl + nbytes; bloc = (byte*)bl + nbytes;
runtime·unlock(&memlock);
return (void*)bl; return (void*)bl;
} }
void void
runtime·SysFree(void *v, uintptr nbytes) runtime·SysFree(void *v, uintptr nbytes)
{ {
runtime·lock(&memlock);
mstats.sys -= nbytes;
// from tiny/mem.c // from tiny/mem.c
// Push pointer back if this is a free // Push pointer back if this is a free
// of the most recent SysAlloc. // of the most recent SysAlloc.
nbytes += (nbytes + Round) & ~Round; nbytes += (nbytes + Round) & ~Round;
if(bloc == (byte*)v+nbytes) if(bloc == (byte*)v+nbytes)
bloc -= nbytes; bloc -= nbytes;
runtime·unlock(&memlock);
} }
void void