race.go raw

   1  // Copyright 2019 The Go Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style
   3  // license that can be found in the LICENSE file.
   4  
   5  //go:build race
   6  
   7  package socket
   8  
   9  import (
  10  	"runtime"
  11  	"unsafe"
  12  )
  13  
  14  // This package reads and writes the Message buffers using a
  15  // direct system call, which the race detector can't see.
  16  // These functions tell the race detector what is going on during the syscall.
  17  
  18  func (m *Message) raceRead() {
  19  	for _, b := range m.Buffers {
  20  		if len(b) > 0 {
  21  			runtime.RaceReadRange(unsafe.Pointer(&b[0]), len(b))
  22  		}
  23  	}
  24  	if b := m.OOB; len(b) > 0 {
  25  		runtime.RaceReadRange(unsafe.Pointer(&b[0]), len(b))
  26  	}
  27  }
  28  func (m *Message) raceWrite() {
  29  	for _, b := range m.Buffers {
  30  		if len(b) > 0 {
  31  			runtime.RaceWriteRange(unsafe.Pointer(&b[0]), len(b))
  32  		}
  33  	}
  34  	if b := m.OOB; len(b) > 0 {
  35  		runtime.RaceWriteRange(unsafe.Pointer(&b[0]), len(b))
  36  	}
  37  }
  38