]> Cypherpunks repositories - gostls13.git/commitdiff
os: fix data race in epipecheck()
authorDmitriy Vyukov <dvyukov@google.com>
Fri, 27 Jul 2012 11:05:13 +0000 (15:05 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Fri, 27 Jul 2012 11:05:13 +0000 (15:05 +0400)
Fixes #3860.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/6443051

src/pkg/os/file_posix.go
src/pkg/os/file_unix.go
src/pkg/os/file_windows.go

index 073bd56a471d4bb21b1f7dc55620c11ac8565cf5..ea42cc67b5128ef2b431dd6322bb453e6dfb1164 100644 (file)
@@ -7,6 +7,7 @@
 package os
 
 import (
+       "sync/atomic"
        "syscall"
        "time"
 )
@@ -15,12 +16,11 @@ func sigpipe() // implemented in package runtime
 
 func epipecheck(file *File, e error) {
        if e == syscall.EPIPE {
-               file.nepipe++
-               if file.nepipe >= 10 {
+               if atomic.AddInt32(&file.nepipe, 1) >= 10 {
                        sigpipe()
                }
        } else {
-               file.nepipe = 0
+               atomic.StoreInt32(&file.nepipe, 0)
        }
 }
 
index 6271c3189ef1d006f720291ec44eb63472d5bfc6..12daa70a760c75df5953fc3c8e2a6b52298645de 100644 (file)
@@ -24,7 +24,7 @@ type file struct {
        fd      int
        name    string
        dirinfo *dirInfo // nil unless directory being read
-       nepipe  int      // number of consecutive EPIPE in Write
+       nepipe  int32    // number of consecutive EPIPE in Write
 }
 
 // Fd returns the integer Unix file descriptor referencing the open file.
index 88fa77bb848e5182d21073ff986c798056b6fe9a..320ee22518c5ec225a5f6c6edffbd94ed5d0608f 100644 (file)
@@ -25,7 +25,6 @@ type file struct {
        fd      syscall.Handle
        name    string
        dirinfo *dirInfo   // nil unless directory being read
-       nepipe  int        // number of consecutive EPIPE in Write
        l       sync.Mutex // used to implement windows pread/pwrite
 }