summaryrefslogtreecommitdiff
path: root/libgo/go/time/sleep.go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-07-16 06:54:42 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-07-16 06:54:42 +0000
commitf4ca453c9530ff24478cae090c9979b97fdd7411 (patch)
tree0e8fda573576bb4181dba29d0e88380a8c38fafd /libgo/go/time/sleep.go
parent84a4a7d4b2fecf754bc0b7fce55b05912a054ef4 (diff)
downloadgcc-f4ca453c9530ff24478cae090c9979b97fdd7411.tar.gz
libgo: Update to Go 1.1.1.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200974 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/time/sleep.go')
-rw-r--r--libgo/go/time/sleep.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/libgo/go/time/sleep.go b/libgo/go/time/sleep.go
index 1e6b4f2e442..591fa27b090 100644
--- a/libgo/go/time/sleep.go
+++ b/libgo/go/time/sleep.go
@@ -18,10 +18,25 @@ type runtimeTimer struct {
i int32
when int64
period int64
- f func(int64, interface{})
+ f func(int64, interface{}) // NOTE: must not be closure
arg interface{}
}
+// when is a helper function for setting the 'when' field of a runtimeTimer.
+// It returns what the time will be, in nanoseconds, Duration d in the future.
+// If d is negative, it is ignored. If the returned value would be less than
+// zero because of an overflow, MaxInt64 is returned.
+func when(d Duration) int64 {
+ if d <= 0 {
+ return nano()
+ }
+ t := nano() + int64(d)
+ if t < 0 {
+ t = 1<<63 - 1 // math.MaxInt64
+ }
+ return t
+}
+
func startTimer(*runtimeTimer)
func stopTimer(*runtimeTimer) bool
@@ -49,7 +64,7 @@ func NewTimer(d Duration) *Timer {
t := &Timer{
C: c,
r: runtimeTimer{
- when: nano() + int64(d),
+ when: when(d),
f: sendTime,
arg: c,
},
@@ -62,9 +77,9 @@ func NewTimer(d Duration) *Timer {
// It returns true if the timer had been active, false if the timer had
// expired or been stopped.
func (t *Timer) Reset(d Duration) bool {
- when := nano() + int64(d)
+ w := when(d)
active := stopTimer(&t.r)
- t.r.when = when
+ t.r.when = w
startTimer(&t.r)
return active
}
@@ -94,7 +109,7 @@ func After(d Duration) <-chan Time {
func AfterFunc(d Duration, f func()) *Timer {
t := &Timer{
r: runtimeTimer{
- when: nano() + int64(d),
+ when: when(d),
f: goFunc,
arg: f,
},