mirror of
https://github.com/golang/go
synced 2024-11-21 22:54:40 -07:00
time: isolate syscall reference in sys.go
R=dsymonds CC=golang-dev https://golang.org/cl/4291052
This commit is contained in:
parent
bc35379763
commit
2ca46a789b
@ -5,9 +5,8 @@
|
||||
package time
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"sync"
|
||||
"container/heap"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// The Timer type represents a single event.
|
||||
@ -126,7 +125,7 @@ func sleeper(sleeperId int64) {
|
||||
dt = maxSleepTime
|
||||
}
|
||||
timerMutex.Unlock()
|
||||
syscall.Sleep(dt)
|
||||
sysSleep(dt)
|
||||
timerMutex.Lock()
|
||||
if currentSleeper != sleeperId {
|
||||
// Another sleeper has been started, making this one redundant.
|
||||
|
@ -44,11 +44,19 @@ func sleep(t, ns int64) (int64, os.Error) {
|
||||
// TODO(cw): use monotonic-time once it's available
|
||||
end := t + ns
|
||||
for t < end {
|
||||
errno := syscall.Sleep(end - t)
|
||||
if errno != 0 && errno != syscall.EINTR {
|
||||
return 0, os.NewSyscallError("sleep", errno)
|
||||
err := sysSleep(end - t)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
t = Nanoseconds()
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func sysSleep(t int64) os.Error {
|
||||
errno := syscall.Sleep(t)
|
||||
if errno != 0 && errno != syscall.EINTR {
|
||||
return os.NewSyscallError("sleep", errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user