Skip to content

Commit 0b12e3d

Browse files
committed
runtime: model wakeableSleep.lock in the race detector
Currently the flight recorder tests are failing in race mode because the race detector doesn't see s.lock, leading to false positives. This has also appeared in the trace tests. Model the lock in the race detector. Fixes #65207. Fixes #65283. Change-Id: I1e9a5c9606536f55fdfc46b5f8443e9c7213c23d Reviewed-on: https://go-review.googlesource.com/c/go/+/560215 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 287f791 commit 0b12e3d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/runtime/trace2.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,13 @@ func newWakeableSleep() *wakeableSleep {
932932
func (s *wakeableSleep) sleep(ns int64) {
933933
resetTimer(s.timer, nanotime()+ns)
934934
lock(&s.lock)
935+
if raceenabled {
936+
raceacquire(unsafe.Pointer(&s.lock))
937+
}
935938
wakeup := s.wakeup
939+
if raceenabled {
940+
racerelease(unsafe.Pointer(&s.lock))
941+
}
936942
unlock(&s.lock)
937943
<-wakeup
938944
stopTimer(s.timer)
@@ -945,6 +951,9 @@ func (s *wakeableSleep) wake() {
945951
// Grab the wakeup channel, which may be nil if we're
946952
// racing with close.
947953
lock(&s.lock)
954+
if raceenabled {
955+
raceacquire(unsafe.Pointer(&s.lock))
956+
}
948957
if s.wakeup != nil {
949958
// Non-blocking send.
950959
//
@@ -956,6 +965,9 @@ func (s *wakeableSleep) wake() {
956965
default:
957966
}
958967
}
968+
if raceenabled {
969+
racerelease(unsafe.Pointer(&s.lock))
970+
}
959971
unlock(&s.lock)
960972
}
961973

@@ -969,11 +981,18 @@ func (s *wakeableSleep) wake() {
969981
func (s *wakeableSleep) close() {
970982
// Set wakeup to nil so that a late timer ends up being a no-op.
971983
lock(&s.lock)
984+
if raceenabled {
985+
raceacquire(unsafe.Pointer(&s.lock))
986+
}
972987
wakeup := s.wakeup
973988
s.wakeup = nil
974989

975990
// Close the channel.
976991
close(wakeup)
992+
993+
if raceenabled {
994+
racerelease(unsafe.Pointer(&s.lock))
995+
}
977996
unlock(&s.lock)
978997
return
979998
}

0 commit comments

Comments
 (0)