mirror of https://github.com/golang/go.git
io/ioutil: fix data race under the race detector
See issue 3970 (it's already marked as Fixed). R=rsc, minux.ma CC=golang-dev https://golang.org/cl/6624059
This commit is contained in:
parent
59b8745328
commit
373dbcb37a
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
@ -130,12 +130,11 @@ func (devNull) Write(p []byte) (int, error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var blackHole = make([]byte, 8192)
|
|
||||||
|
|
||||||
func (devNull) ReadFrom(r io.Reader) (n int64, err error) {
|
func (devNull) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
|
buf := blackHole()
|
||||||
readSize := 0
|
readSize := 0
|
||||||
for {
|
for {
|
||||||
readSize, err = r.Read(blackHole)
|
readSize, err = r.Read(buf)
|
||||||
n += int64(readSize)
|
n += int64(readSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue