aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/runtime/time.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-06-24 16:19:07 +0200
committerRon Evans <[email protected]>2024-08-17 11:49:14 +0200
commite865db232bad0a2a5152749edd6a9ce32557c8b7 (patch)
tree26859de80e78afdab1602a4730a4d79ec38916f2 /src/runtime/time.go
parentdb2a06a9bb4a16850511294b7418fca6422e668b (diff)
downloadtinygo-e865db232bad0a2a5152749edd6a9ce32557c8b7.tar.gz
tinygo-e865db232bad0a2a5152749edd6a9ce32557c8b7.zip
runtime: implement timers for Go 1.23
There were a number of changes in time.Timer/time.Ticker that need a separate implementation for Go 1.22 and Go 1.23.
Diffstat (limited to 'src/runtime/time.go')
-rw-r--r--src/runtime/time.go30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go
index 4fa3a418b..50bf61cf3 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -4,7 +4,7 @@ package runtime
type timerNode struct {
next *timerNode
timer *timer
- callback func(*timerNode)
+ callback func(node *timerNode, delta int64)
}
// whenTicks returns the (absolute) time when this timer should trigger next.
@@ -12,17 +12,6 @@ func (t *timerNode) whenTicks() timeUnit {
return nanosecondsToTicks(t.timer.when)
}
-// Defined in the time package, implemented here in the runtime.
-//
-//go:linkname startTimer time.startTimer
-func startTimer(tim *timer) {
- addTimer(&timerNode{
- timer: tim,
- callback: timerCallback,
- })
- scheduleLog("adding timer")
-}
-
// timerCallback is called when a timer expires. It makes sure to call the
// callback in the time package and to re-add the timer to the queue if this is
// a ticker (repeating timer).
@@ -32,11 +21,11 @@ func startTimer(tim *timer) {
// dependency causes timerQueue not to get optimized away.
// If timerQueue doesn't get optimized away, small programs (that don't call
// time.NewTimer etc) would still pay the cost of these timers.
-func timerCallback(tn *timerNode) {
+func timerCallback(tn *timerNode, delta int64) {
// Run timer function (implemented in the time package).
// The seq parameter to the f function is not used in the time
// package so is left zero.
- tn.timer.f(tn.timer.arg, 0)
+ tn.timer.callCallback(delta)
// If this is a periodic timer (a ticker), re-add it to the queue.
if tn.timer.period != 0 {
@@ -44,16 +33,3 @@ func timerCallback(tn *timerNode) {
addTimer(tn)
}
}
-
-//go:linkname stopTimer time.stopTimer
-func stopTimer(tim *timer) bool {
- return removeTimer(tim)
-}
-
-//go:linkname resetTimer time.resetTimer
-func resetTimer(tim *timer, when int64) bool {
- tim.when = when
- removed := removeTimer(tim)
- startTimer(tim)
- return removed
-}