mirror of
https://github.com/golang/go
synced 2024-11-18 19:44:46 -07:00
runtime: convert clearpools/registerPoolCleanup to Go
LGTM=bradfitz, rsc R=golang-codereviews, bradfitz, rsc CC=golang-codereviews, khr https://golang.org/cl/133240043
This commit is contained in:
parent
ac49e6735b
commit
60447c2d95
@ -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:
|
||||
//
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,6 @@ const (
|
||||
func gosched()
|
||||
func starttheworld()
|
||||
func stoptheworld()
|
||||
func clearpools()
|
||||
|
||||
// exported value for testing
|
||||
var hashLoad = loadFactor
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user