Commit 2ca46a78 authored by Russ Cox's avatar Russ Cox

time: isolate syscall reference in sys.go

R=dsymonds
CC=golang-dev
https://golang.org/cl/4291052
parent bc353797
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
package time package time
import ( import (
"syscall"
"sync"
"container/heap" "container/heap"
"sync"
) )
// The Timer type represents a single event. // The Timer type represents a single event.
...@@ -126,7 +125,7 @@ func sleeper(sleeperId int64) { ...@@ -126,7 +125,7 @@ func sleeper(sleeperId int64) {
dt = maxSleepTime dt = maxSleepTime
} }
timerMutex.Unlock() timerMutex.Unlock()
syscall.Sleep(dt) sysSleep(dt)
timerMutex.Lock() timerMutex.Lock()
if currentSleeper != sleeperId { if currentSleeper != sleeperId {
// Another sleeper has been started, making this one redundant. // Another sleeper has been started, making this one redundant.
......
...@@ -44,11 +44,19 @@ func sleep(t, ns int64) (int64, os.Error) { ...@@ -44,11 +44,19 @@ func sleep(t, ns int64) (int64, os.Error) {
// TODO(cw): use monotonic-time once it's available // TODO(cw): use monotonic-time once it's available
end := t + ns end := t + ns
for t < end { for t < end {
errno := syscall.Sleep(end - t) err := sysSleep(end - t)
if errno != 0 && errno != syscall.EINTR { if err != nil {
return 0, os.NewSyscallError("sleep", errno) return 0, err
} }
t = Nanoseconds() t = Nanoseconds()
} }
return t, nil 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
}
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