diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-10-23 04:31:11 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-10-23 04:31:11 +0000 |
commit | 4ccad563d2a3559f0557bfb177bcf45144219bdf (patch) | |
tree | 46bb86f514fbf6bad82da48e69a18fb09d878834 /libgo/go/io | |
parent | 0b7463235f0e23c624d1911c9b15f531108cc5a6 (diff) | |
download | gcc-4ccad563d2a3559f0557bfb177bcf45144219bdf.zip gcc-4ccad563d2a3559f0557bfb177bcf45144219bdf.tar.gz gcc-4ccad563d2a3559f0557bfb177bcf45144219bdf.tar.bz2 |
libgo: Update to current sources.
From-SVN: r192704
Diffstat (limited to 'libgo/go/io')
-rw-r--r-- | libgo/go/io/ioutil/blackhole.go | 13 | ||||
-rw-r--r-- | libgo/go/io/ioutil/blackhole_race.go | 13 | ||||
-rw-r--r-- | libgo/go/io/ioutil/ioutil.go | 5 | ||||
-rw-r--r-- | libgo/go/io/ioutil/tempfile.go | 4 |
4 files changed, 32 insertions, 3 deletions
diff --git a/libgo/go/io/ioutil/blackhole.go b/libgo/go/io/ioutil/blackhole.go new file mode 100644 index 0000000..c127bdb --- /dev/null +++ b/libgo/go/io/ioutil/blackhole.go @@ -0,0 +1,13 @@ +// Copyright 2012 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. + +// +build !race + +package ioutil + +var blackHoleBuf = make([]byte, 8192) + +func blackHole() []byte { + return blackHoleBuf +} diff --git a/libgo/go/io/ioutil/blackhole_race.go b/libgo/go/io/ioutil/blackhole_race.go new file mode 100644 index 0000000..eb640e0 --- /dev/null +++ b/libgo/go/io/ioutil/blackhole_race.go @@ -0,0 +1,13 @@ +// Copyright 2012 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. + +// +build race + +package ioutil + +// Replaces the normal fast implementation with slower but formally correct one. + +func blackHole() []byte { + return make([]byte, 8192) +} diff --git a/libgo/go/io/ioutil/ioutil.go b/libgo/go/io/ioutil/ioutil.go index f072b8c..31c7729 100644 --- a/libgo/go/io/ioutil/ioutil.go +++ b/libgo/go/io/ioutil/ioutil.go @@ -130,12 +130,11 @@ func (devNull) Write(p []byte) (int, error) { return len(p), nil } -var blackHole = make([]byte, 8192) - func (devNull) ReadFrom(r io.Reader) (n int64, err error) { + buf := blackHole() readSize := 0 for { - readSize, err = r.Read(blackHole) + readSize, err = r.Read(buf) n += int64(readSize) if err != nil { if err == io.EOF { diff --git a/libgo/go/io/ioutil/tempfile.go b/libgo/go/io/ioutil/tempfile.go index 42d2e67..257e05d 100644 --- a/libgo/go/io/ioutil/tempfile.go +++ b/libgo/go/io/ioutil/tempfile.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "strconv" + "sync" "time" ) @@ -16,18 +17,21 @@ import ( // chance the file doesn't exist yet - keeps the number of tries in // TempFile to a minimum. var rand uint32 +var randmu sync.Mutex func reseed() uint32 { return uint32(time.Now().UnixNano() + int64(os.Getpid())) } func nextSuffix() string { + randmu.Lock() r := rand if r == 0 { r = reseed() } r = r*1664525 + 1013904223 // constants from Numerical Recipes rand = r + randmu.Unlock() return strconv.Itoa(int(1e9 + r%1e9))[1:] } |