mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: factor stoptheworld/starttheworld pattern
There are several steps to stopping and starting the world and currently they're open-coded in several places. The garbage collector is the only thing that needs to stop and start the world in a non-trivial pattern. Replace all other uses with calls to higher-level functions that implement the entire pattern necessary to stop and start the world. This is a pure refectoring and should not change any code semantics. In the following commits, we'll make changes that are easier to do with this abstraction in place. This commit renames the old starttheworld to startTheWorldWithSema. This is a slight misnomer right now because the callers release worldsema just before calling this. However, a later commit will swap these and I don't want to think of another name in the mean time. Change-Id: I5dc97f87b44fb98963c49c777d7053653974c911 Reviewed-on: https://go-review.googlesource.com/10154 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
5f7060afd2
commit
a1da255aa0
8 changed files with 88 additions and 97 deletions
|
|
@ -15,20 +15,15 @@ import "unsafe"
|
|||
|
||||
//go:linkname runtime_debug_WriteHeapDump runtime/debug.WriteHeapDump
|
||||
func runtime_debug_WriteHeapDump(fd uintptr) {
|
||||
semacquire(&worldsema, false)
|
||||
gp := getg()
|
||||
gp.m.preemptoff = "write heap dump"
|
||||
systemstack(stoptheworld)
|
||||
stopTheWorld("write heap dump")
|
||||
|
||||
systemstack(func() {
|
||||
writeheapdump_m(fd)
|
||||
})
|
||||
|
||||
gp.m.preemptoff = ""
|
||||
gp.m.locks++
|
||||
semrelease(&worldsema)
|
||||
systemstack(starttheworld)
|
||||
gp.m.locks--
|
||||
getg().m.locks++ // TODO: Is this necessary?
|
||||
startTheWorld()
|
||||
getg().m.locks--
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue