aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/time.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-04-11 14:20:54 -0700
committerIan Lance Taylor <iant@golang.org>2019-10-23 07:43:18 +0000
commitab3f1a23b6c29a110423d6fd6bf2b01fa62a6fb2 (patch)
tree38e2a45179cd9748a8bad2099f32fbe3dc9a2e37 /src/runtime/time.go
parentc824420d4744bd3e11128c000d88c24859602d46 (diff)
downloadgo-ab3f1a23b6c29a110423d6fd6bf2b01fa62a6fb2.tar.gz
go-ab3f1a23b6c29a110423d6fd6bf2b01fa62a6fb2.zip
runtime: add race detector support for new timers
Since the new timers run on g0, which does not have a race context, we add a race context field to the P, and use that for timer functions. This works since all timer functions are in the standard library. Updates #27707 Change-Id: I8a5b727b4ddc8ca6fc60eb6d6f5e9819245e395b Reviewed-on: https://go-review.googlesource.com/c/go/+/171882 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/time.go')
-rw-r--r--src/runtime/time.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go
index 4bc819f023..fea5d6871c 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -9,6 +9,7 @@ package runtime
import (
"internal/cpu"
"runtime/internal/atomic"
+ "runtime/internal/sys"
"unsafe"
)
@@ -1095,6 +1096,13 @@ func runtimer(pp *p, now int64) int64 {
// runOneTimer runs a single timer.
// The caller must have locked the timers for pp.
func runOneTimer(pp *p, t *timer, now int64) {
+ if raceenabled {
+ if pp.timerRaceCtx == 0 {
+ pp.timerRaceCtx = racegostart(funcPC(runtimer) + sys.PCQuantum)
+ }
+ raceacquirectx(pp.timerRaceCtx, unsafe.Pointer(t))
+ }
+
f := t.f
arg := t.arg
seq := t.seq
@@ -1119,10 +1127,24 @@ func runOneTimer(pp *p, t *timer, now int64) {
}
}
+ if raceenabled {
+ // Temporarily use the P's racectx for g0.
+ gp := getg()
+ if gp.racectx != 0 {
+ throw("runOneTimer: unexpected racectx")
+ }
+ gp.racectx = pp.timerRaceCtx
+ }
+
// Note that since timers are locked here, f may not call
// addtimer or resettimer.
f(arg, seq)
+
+ if raceenabled {
+ gp := getg()
+ gp.racectx = 0
+ }
}
func timejump() *p {