aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/time
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-03-24 23:46:17 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-03-24 23:46:17 +0000
commit8039ca76a5705ae5052b20cee64110c32545c4fc (patch)
tree9319bca77115a32f6a0b5e8bcd651465b14c76da /libgo/go/time
parent7114321ee4f521ea9fbdd08a4c23b361181f3658 (diff)
downloadgcc-8039ca76a5705ae5052b20cee64110c32545c4fc.zip
gcc-8039ca76a5705ae5052b20cee64110c32545c4fc.tar.gz
gcc-8039ca76a5705ae5052b20cee64110c32545c4fc.tar.bz2
Update to current version of Go library.
From-SVN: r171427
Diffstat (limited to 'libgo/go/time')
-rw-r--r--libgo/go/time/sleep.go30
-rw-r--r--libgo/go/time/sleep_test.go4
-rw-r--r--libgo/go/time/sys.go62
-rw-r--r--libgo/go/time/time.go26
-rw-r--r--libgo/go/time/time_test.go12
5 files changed, 80 insertions, 54 deletions
diff --git a/libgo/go/time/sleep.go b/libgo/go/time/sleep.go
index 833552d..3bc253c 100644
--- a/libgo/go/time/sleep.go
+++ b/libgo/go/time/sleep.go
@@ -5,10 +5,8 @@
package time
import (
- "os"
- "syscall"
- "sync"
"container/heap"
+ "sync"
)
// The Timer type represents a single event.
@@ -47,30 +45,6 @@ func init() {
timers.Push(&Timer{t: forever}) // sentinel
}
-// Sleep pauses the current goroutine for at least ns nanoseconds.
-// Higher resolution sleeping may be provided by syscall.Nanosleep
-// on some operating systems.
-func Sleep(ns int64) os.Error {
- _, err := sleep(Nanoseconds(), ns)
- return err
-}
-
-// sleep takes the current time and a duration,
-// pauses for at least ns nanoseconds, and
-// returns the current time and an error.
-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)
- }
- t = Nanoseconds()
- }
- return t, nil
-}
-
// NewTimer creates a new Timer that will send
// the current time on its channel after at least ns nanoseconds.
func NewTimer(ns int64) *Timer {
@@ -151,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.
diff --git a/libgo/go/time/sleep_test.go b/libgo/go/time/sleep_test.go
index 8bf599c..5fe4d7f 100644
--- a/libgo/go/time/sleep_test.go
+++ b/libgo/go/time/sleep_test.go
@@ -132,7 +132,9 @@ func TestAfterStop(t *testing.T) {
}
}
-var slots = []int{5, 3, 6, 6, 6, 1, 1, 2, 7, 9, 4, 8, 0}
+// For gccgo omit 0 for now because it can take too long to start the
+// thread.
+var slots = []int{5, 3, 6, 6, 6, 1, 1, 2, 7, 9, 4, 8, /*0*/}
type afterResult struct {
slot int
diff --git a/libgo/go/time/sys.go b/libgo/go/time/sys.go
new file mode 100644
index 0000000..63f4cbf
--- /dev/null
+++ b/libgo/go/time/sys.go
@@ -0,0 +1,62 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package time
+
+import (
+ "os"
+ "syscall"
+)
+
+// Seconds reports the number of seconds since the Unix epoch,
+// January 1, 1970 00:00:00 UTC.
+func Seconds() int64 {
+ sec, _, err := os.Time()
+ if err != nil {
+ panic(err)
+ }
+ return sec
+}
+
+// Nanoseconds reports the number of nanoseconds since the Unix epoch,
+// January 1, 1970 00:00:00 UTC.
+func Nanoseconds() int64 {
+ sec, nsec, err := os.Time()
+ if err != nil {
+ panic(err)
+ }
+ return sec*1e9 + nsec
+}
+
+// Sleep pauses the current goroutine for at least ns nanoseconds.
+// Higher resolution sleeping may be provided by syscall.Nanosleep
+// on some operating systems.
+func Sleep(ns int64) os.Error {
+ _, err := sleep(Nanoseconds(), ns)
+ return err
+}
+
+// sleep takes the current time and a duration,
+// pauses for at least ns nanoseconds, and
+// returns the current time and an error.
+func sleep(t, ns int64) (int64, os.Error) {
+ // TODO(cw): use monotonic-time once it's available
+ end := t + ns
+ for t < end {
+ 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
+}
diff --git a/libgo/go/time/time.go b/libgo/go/time/time.go
index 4abd112..40338f7 100644
--- a/libgo/go/time/time.go
+++ b/libgo/go/time/time.go
@@ -6,30 +6,6 @@
// displaying time.
package time
-import (
- "os"
-)
-
-// Seconds reports the number of seconds since the Unix epoch,
-// January 1, 1970 00:00:00 UTC.
-func Seconds() int64 {
- sec, _, err := os.Time()
- if err != nil {
- panic(err)
- }
- return sec
-}
-
-// Nanoseconds reports the number of nanoseconds since the Unix epoch,
-// January 1, 1970 00:00:00 UTC.
-func Nanoseconds() int64 {
- sec, nsec, err := os.Time()
- if err != nil {
- panic(err)
- }
- return sec*1e9 + nsec
-}
-
// Days of the week.
const (
Sunday = iota
@@ -47,7 +23,7 @@ type Time struct {
Month, Day int // Jan-2 is 1, 2
Hour, Minute, Second int // 15:04:05 is 15, 4, 5.
Weekday int // Sunday, Monday, ...
- ZoneOffset int // seconds east of UTC, e.g. -7*60 for -0700
+ ZoneOffset int // seconds east of UTC, e.g. -7*60*60 for -0700
Zone string // e.g., "MST"
}
diff --git a/libgo/go/time/time_test.go b/libgo/go/time/time_test.go
index c86bca1..1d83291 100644
--- a/libgo/go/time/time_test.go
+++ b/libgo/go/time/time_test.go
@@ -19,6 +19,18 @@ func init() {
os.Setenv("TZ", "America/Los_Angeles")
}
+// We should be in PST/PDT, but if the time zone files are missing we
+// won't be. The purpose of this test is to at least explain why some of
+// the subsequent tests fail.
+func TestZoneData(t *testing.T) {
+ lt := LocalTime()
+ // PST is 8 hours west, PDT is 7 hours west. We could use the name but it's not unique.
+ if off := lt.ZoneOffset; off != -8*60*60 && off != -7*60*60 {
+ t.Errorf("Unable to find US Pacific time zone data for testing; time zone is %q offset %d", lt.Zone, off)
+ t.Error("Likely problem: the time zone files have not been installed.")
+ }
+}
+
type TimeTest struct {
seconds int64
golden Time