Commit 88ee849a authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

net: annotate Read/Write for race detector

Fixes #6167.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13052043
parent d017f578
...@@ -15,7 +15,10 @@ import ( ...@@ -15,7 +15,10 @@ import (
"unsafe" "unsafe"
) )
var initErr error var (
initErr error
ioSync uint64
)
// CancelIo Windows API cancels all outstanding IO for a particular // CancelIo Windows API cancels all outstanding IO for a particular
// socket on current thread. To overcome that limitation, we run // socket on current thread. To overcome that limitation, we run
...@@ -448,6 +451,9 @@ func (fd *netFD) Read(buf []byte) (int, error) { ...@@ -448,6 +451,9 @@ func (fd *netFD) Read(buf []byte) (int, error) {
if err == nil && n == 0 { if err == nil && n == 0 {
err = io.EOF err = io.EOF
} }
if raceenabled {
raceAcquire(unsafe.Pointer(&ioSync))
}
return n, err return n, err
} }
...@@ -480,6 +486,9 @@ func (fd *netFD) Write(buf []byte) (int, error) { ...@@ -480,6 +486,9 @@ func (fd *netFD) Write(buf []byte) (int, error) {
return 0, err return 0, err
} }
defer fd.writeUnlock() defer fd.writeUnlock()
if raceenabled {
raceReleaseMerge(unsafe.Pointer(&ioSync))
}
o := &fd.wop o := &fd.wop
o.InitBuf(buf) o.InitBuf(buf)
return iosrv.ExecIO(o, "WSASend", func(o *operation) error { return iosrv.ExecIO(o, "WSASend", func(o *operation) error {
......
// 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)
}
// 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) {
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment