]> Cypherpunks repositories - gostls13.git/commitdiff
fix another gc bug, one that i have only imagined,
authorRuss Cox <rsc@golang.org>
Tue, 16 Jun 2009 04:31:56 +0000 (21:31 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 16 Jun 2009 04:31:56 +0000 (21:31 -0700)
not observed: do not use malloc to allocate stacks
during garbage collection, because it would make the
malloc data structures change underfoot.

R=r
DELTA=6  (3 added, 0 deleted, 3 changed)
OCL=30323
CL=30326

src/pkg/runtime/malloc.c
src/pkg/runtime/mgc0.c
src/pkg/runtime/runtime.h

index 81cdfb30019d66d5c279d61e949a34c63c14cd28..84c802f94a98a8464ec207d26eb61b70da2f5378 100644 (file)
@@ -274,7 +274,7 @@ stackalloc(uint32 n)
        uint32 *ref;
 
 //return oldmal(n);
-       if(m->mallocing) {
+       if(m->mallocing || m->gcing) {
                lock(&stacks);
                if(stacks.size == 0)
                        FixAlloc_Init(&stacks, n, SysAlloc, nil, nil);
@@ -298,7 +298,7 @@ stackfree(void *v)
 {
 //return;
 
-       if(m->mallocing) {
+       if(m->mallocing || m->gcing) {
                lock(&stacks);
                FixAlloc_Free(&stacks, v);
                unlock(&stacks);
index d58d6ce44d14027fae4f58663e3fa62acd09f006..75f2003783d891f73781338d0e74dbc4801ba3f1 100644 (file)
@@ -215,6 +215,7 @@ gc(int32 force)
        if(gcpercent < 0)
                return;
 
+       m->gcing = 1;
        semacquire(&gcsema);
        gosave(&g->sched);      // update g's stack pointer for scanstack
        stoptheworld();
@@ -228,4 +229,5 @@ gc(int32 force)
        starttheworld();
        gosave(&g->sched);      // update g's stack pointer for debugging
        semrelease(&gcsema);
+       m->gcing = 0;
 }
index 749364f954fb138be3dac0cf25f9cf8c9c349ab7..dc80a088dc60f1cab420788ca3ab5268c38e51a0 100644 (file)
@@ -177,6 +177,7 @@ struct      M
        int32   siz2;
        int32   id;
        int32   mallocing;
+       int32   gcing;
        int32   locks;
        Note    havenextg;
        G*      nextg;