mirror of
https://github.com/golang/go
synced 2024-11-25 03:37:58 -07:00
net: annotate Read/Write for race detector
Fixes #6167. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/13052043
This commit is contained in:
parent
d017f578d0
commit
88ee849a8a
@ -15,7 +15,10 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var initErr error
|
||||
var (
|
||||
initErr error
|
||||
ioSync uint64
|
||||
)
|
||||
|
||||
// CancelIo Windows API cancels all outstanding IO for a particular
|
||||
// socket on current thread. To overcome that limitation, we run
|
||||
@ -448,6 +451,9 @@ func (fd *netFD) Read(buf []byte) (int, error) {
|
||||
if err == nil && n == 0 {
|
||||
err = io.EOF
|
||||
}
|
||||
if raceenabled {
|
||||
raceAcquire(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
@ -480,6 +486,9 @@ func (fd *netFD) Write(buf []byte) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
defer fd.writeUnlock()
|
||||
if raceenabled {
|
||||
raceReleaseMerge(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
o := &fd.wop
|
||||
o.InitBuf(buf)
|
||||
return iosrv.ExecIO(o, "WSASend", func(o *operation) error {
|
||||
|
31
src/pkg/net/race.go
Normal file
31
src/pkg/net/race.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2013 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
|
||||
// +build windows
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const raceenabled = true
|
||||
|
||||
func raceAcquire(addr unsafe.Pointer) {
|
||||
runtime.RaceAcquire(addr)
|
||||
}
|
||||
|
||||
func raceReleaseMerge(addr unsafe.Pointer) {
|
||||
runtime.RaceReleaseMerge(addr)
|
||||
}
|
||||
|
||||
func raceReadRange(addr unsafe.Pointer, len int) {
|
||||
runtime.RaceReadRange(addr, len)
|
||||
}
|
||||
|
||||
func raceWriteRange(addr unsafe.Pointer, len int) {
|
||||
runtime.RaceWriteRange(addr, len)
|
||||
}
|
26
src/pkg/net/race0.go
Normal file
26
src/pkg/net/race0.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2013 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
|
||||
// +build windows
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const raceenabled = false
|
||||
|
||||
func raceAcquire(addr unsafe.Pointer) {
|
||||
}
|
||||
|
||||
func raceReleaseMerge(addr unsafe.Pointer) {
|
||||
}
|
||||
|
||||
func raceReadRange(addr unsafe.Pointer, len int) {
|
||||
}
|
||||
|
||||
func raceWriteRange(addr unsafe.Pointer, len int) {
|
||||
}
|
Loading…
Reference in New Issue
Block a user