]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert clearpools/registerPoolCleanup to Go
authorDmitriy Vyukov <dvyukov@google.com>
Tue, 2 Sep 2014 16:03:48 +0000 (20:03 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Tue, 2 Sep 2014 16:03:48 +0000 (20:03 +0400)
LGTM=bradfitz, rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews, khr
https://golang.org/cl/133240043

src/pkg/runtime/mgc0.c
src/pkg/runtime/mgc0.go
src/pkg/runtime/stubs.go
src/pkg/runtime/thunk.s

index 0aacbcebaf785d015f765a95820c2a8a364a6188..4d75ed5a2eb728b9723bae7ceff997ef24c7c535 100644 (file)
@@ -82,39 +82,6 @@ enum {
 // Initialized from $GOGC.  GOGC=off means no gc.
 extern int32 runtime·gcpercent;
 
-static FuncVal* poolcleanup;
-
-void
-sync·runtime_registerPoolCleanup(FuncVal *f)
-{
-       poolcleanup = f;
-}
-
-void
-runtime·clearpools(void)
-{
-       P *p, **pp;
-       MCache *c;
-       int32 i;
-
-       // clear sync.Pool's
-       if(poolcleanup != nil)
-               reflect·call(poolcleanup, nil, 0, 0);
-
-       for(pp=runtime·allp; p=*pp; pp++) {
-               // clear tinyalloc pool
-               c = p->mcache;
-               if(c != nil) {
-                       c->tiny = nil;
-                       c->tinysize = 0;
-                       c->sudogcache = nil;
-               }
-               // clear defer pools
-               for(i=0; i<nelem(p->deferpool); i++)
-                       p->deferpool[i] = nil;
-       }
-}
-
 // Holding worldsema grants an M the right to try to stop the world.
 // The procedure is:
 //
index 275c7ed676badbab7208fb7052839de5fb868d9e..93af63e63e937905315cae682df56f14f5612e84 100644 (file)
@@ -39,3 +39,32 @@ func freeOSMemory() {
        gogc(2) // force GC and do eager sweep
        onM(&scavenge_m)
 }
+
+var poolcleanup func()
+
+func registerPoolCleanup(f func()) {
+       poolcleanup = f
+}
+
+func clearpools() {
+       // clear sync.Pools
+       if poolcleanup != nil {
+               poolcleanup()
+       }
+
+       for _, p := range &allp {
+               if p == nil {
+                       break
+               }
+               // clear tinyalloc pool
+               if c := p.mcache; c != nil {
+                       c.tiny = nil
+                       c.tinysize = 0
+                       c.sudogcache = nil
+               }
+               // clear defer pools
+               for i := range p.deferpool {
+                       p.deferpool[i] = nil
+               }
+       }
+}
index 2e5c0481ab68d5af6537fcc4273edb8a5f14d1ef..e057eb06592c9f5b21b9aaa0c74d10b6257112a4 100644 (file)
@@ -110,7 +110,6 @@ const (
 func gosched()
 func starttheworld()
 func stoptheworld()
-func clearpools()
 
 // exported value for testing
 var hashLoad = loadFactor
index 75e52c81c1d80481448f03b50b36e100eec9c196..57943ea9972c54feb9d71ec024928efcda3581f0 100644 (file)
@@ -38,6 +38,9 @@ TEXT sync·runtime_Semacquire(SB),NOSPLIT,$0-0
 TEXT sync·runtime_Semrelease(SB),NOSPLIT,$0-0
        JMP     runtime·asyncsemrelease(SB)
 
+TEXT sync·runtime_registerPoolCleanup(SB),NOSPLIT,$0-0
+       JMP     runtime·registerPoolCleanup(SB)
+
 TEXT net·runtime_Semacquire(SB),NOSPLIT,$0-0
        JMP     runtime·asyncsemacquire(SB)