]> Cypherpunks repositories - gostls13.git/commitdiff
time: isolate syscall reference in sys.go
authorRuss Cox <rsc@golang.org>
Thu, 17 Mar 2011 17:46:05 +0000 (13:46 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 17 Mar 2011 17:46:05 +0000 (13:46 -0400)
R=dsymonds
CC=golang-dev
https://golang.org/cl/4291052

src/pkg/time/sleep.go
src/pkg/time/sys.go

index 7b3f01f01e5a0c32853181a4e50aac4d68363a7e..3bc253c94a3908c891bdd6da4bb9093fa68f7d18 100644 (file)
@@ -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.
index 8a2e6fadc21320aa8b43d27d7129df2041b0b867..63f4cbf3d7795f2805b5d240a3e9cd164479b975 100644 (file)
@@ -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
+}