Commit 7d84245a authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: implement time.Sleep for new timers

Updates #27707

Change-Id: I51da8a04ec12ba1efa435e86e3a15d4d13c96c45
Reviewed-on: https://go-review.googlesource.com/c/go/+/171879
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMichael Knyszek <mknyszek@google.com>
parent 432ca0ea
...@@ -229,7 +229,31 @@ func timeSleep(ns int64) { ...@@ -229,7 +229,31 @@ func timeSleep(ns int64) {
timeSleepOld(ns) timeSleepOld(ns)
return return
} }
throw("new timeSleep not yet implemented")
if ns <= 0 {
return
}
gp := getg()
t := gp.timer
if t == nil {
t = new(timer)
gp.timer = t
}
t.f = goroutineReady
t.arg = gp
t.nextwhen = nanotime() + ns
gopark(resetForSleep, unsafe.Pointer(t), waitReasonSleep, traceEvGoSleep, 1)
}
// resetForSleep is called after the goroutine is parked for timeSleep.
// We can't call resettimer in timeSleep itself because if this is a short
// sleep and there are many goroutines then the P can wind up running the
// timer function, goroutineReady, before the goroutine has been parked.
func resetForSleep(gp *g, ut unsafe.Pointer) bool {
t := (*timer)(ut)
resettimer(t, t.nextwhen)
return true
} }
func timeSleepOld(ns int64) { func timeSleepOld(ns int64) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment