mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: add new cleantimers function
Also add a skeleton of the runOneTimer function. Updates #27707 Change-Id: Ic6a0279354a57295f823093704b7e152ce5d769d Reviewed-on: https://go-review.googlesource.com/c/go/+/171835 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
daeb5efb20
commit
4665470147
1 changed files with 52 additions and 3 deletions
|
|
@ -151,6 +151,9 @@ type timersBucket struct {
|
||||||
// timerMoving -> panic: resettimer called on active timer
|
// timerMoving -> panic: resettimer called on active timer
|
||||||
// timerModifiedXX -> panic: resettimer called on active timer
|
// timerModifiedXX -> panic: resettimer called on active timer
|
||||||
// timerModifying -> panic: resettimer called on active timer
|
// timerModifying -> panic: resettimer called on active timer
|
||||||
|
// cleantimers (looks in P's timer heap):
|
||||||
|
// timerDeleted -> timerRemoving -> timerRemoved
|
||||||
|
// timerModifiedXX -> timerMoving -> timerWaiting
|
||||||
|
|
||||||
// Values for the timer status field.
|
// Values for the timer status field.
|
||||||
const (
|
const (
|
||||||
|
|
@ -763,9 +766,49 @@ func timerproc(tb *timersBucket) {
|
||||||
// slows down addtimer. Reports whether no timer problems were found.
|
// slows down addtimer. Reports whether no timer problems were found.
|
||||||
// The caller must have locked the timers for pp.
|
// The caller must have locked the timers for pp.
|
||||||
func cleantimers(pp *p) bool {
|
func cleantimers(pp *p) bool {
|
||||||
// TODO: write this.
|
for {
|
||||||
throw("cleantimers")
|
if len(pp.timers) == 0 {
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
t := pp.timers[0]
|
||||||
|
if t.pp.ptr() != pp {
|
||||||
|
throw("cleantimers: bad p")
|
||||||
|
}
|
||||||
|
switch s := atomic.Load(&t.status); s {
|
||||||
|
case timerDeleted:
|
||||||
|
if !atomic.Cas(&t.status, s, timerRemoving) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !dodeltimer0(pp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
case timerModifiedEarlier, timerModifiedLater:
|
||||||
|
if !atomic.Cas(&t.status, s, timerMoving) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Now we can change the when field.
|
||||||
|
t.when = t.nextwhen
|
||||||
|
// Move t to the right position.
|
||||||
|
if !dodeltimer0(pp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !doaddtimer(pp, t) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if s == timerModifiedEarlier {
|
||||||
|
atomic.Xadd(&pp.adjustTimers, -1)
|
||||||
|
}
|
||||||
|
if !atomic.Cas(&t.status, timerMoving, timerWaiting) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// Head of timers does not need adjustment.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// moveTimers moves a slice of timers to pp. The slice has been taken
|
// moveTimers moves a slice of timers to pp. The slice has been taken
|
||||||
|
|
@ -797,6 +840,12 @@ func runtimer(pp *p, now int64) int64 {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runOneTimer runs a single timer.
|
||||||
|
// The caller must have locked the timers for pp.
|
||||||
|
func runOneTimer(pp *p, t *timer, now int64) {
|
||||||
|
throw("runOneTimer: not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func timejump() *g {
|
func timejump() *g {
|
||||||
if faketime == 0 {
|
if faketime == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue