aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mprof.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2015-05-15 16:00:50 -0400
committerAustin Clements <austin@google.com>2015-05-18 14:55:25 +0000
commita1da255aa0b962231d80e594abe300200e6b4c73 (patch)
tree5f96d6b0c32205c6836af6c748787464dd49d871 /src/runtime/mprof.go
parent5f7060afd2dea927ac64804c7e4639f6635c3bb7 (diff)
downloadgo-a1da255aa0b962231d80e594abe300200e6b4c73.tar.gz
go-a1da255aa0b962231d80e594abe300200e6b4c73.zip
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>
Diffstat (limited to 'src/runtime/mprof.go')
-rw-r--r--src/runtime/mprof.go18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go
index 4544344780..a618bd5e81 100644
--- a/src/runtime/mprof.go
+++ b/src/runtime/mprof.go
@@ -521,9 +521,7 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
n = NumGoroutine()
if n <= len(p) {
gp := getg()
- semacquire(&worldsema, false)
- gp.m.preemptoff = "profile"
- systemstack(stoptheworld)
+ stopTheWorld("profile")
n = NumGoroutine()
if n <= len(p) {
@@ -544,9 +542,7 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
}
}
- gp.m.preemptoff = ""
- semrelease(&worldsema)
- systemstack(starttheworld)
+ startTheWorld()
}
return n, ok
@@ -565,10 +561,7 @@ func saveg(pc, sp uintptr, gp *g, r *StackRecord) {
// into buf after the trace for the current goroutine.
func Stack(buf []byte, all bool) int {
if all {
- semacquire(&worldsema, false)
- gp := getg()
- gp.m.preemptoff = "stack trace"
- systemstack(stoptheworld)
+ stopTheWorld("stack trace")
}
n := 0
@@ -590,10 +583,7 @@ func Stack(buf []byte, all bool) int {
}
if all {
- gp := getg()
- gp.m.preemptoff = ""
- semrelease(&worldsema)
- systemstack(starttheworld)
+ startTheWorld()
}
return n
}