gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/internal/socket/race.go (about)

     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  // +build race
     7  
     8  package socket
     9  
    10  import (
    11  	"runtime"
    12  	"unsafe"
    13  )
    14  
    15  // This package reads and writes the Message buffers using a
    16  // direct system call, which the race detector can't see.
    17  // These functions tell the race detector what is going on during the syscall.
    18  
    19  func (m *Message) raceRead() {
    20  	for _, b := range m.Buffers {
    21  		if len(b) > 0 {
    22  			runtime.RaceReadRange(unsafe.Pointer(&b[0]), len(b))
    23  		}
    24  	}
    25  	if b := m.OOB; len(b) > 0 {
    26  		runtime.RaceReadRange(unsafe.Pointer(&b[0]), len(b))
    27  	}
    28  }
    29  func (m *Message) raceWrite() {
    30  	for _, b := range m.Buffers {
    31  		if len(b) > 0 {
    32  			runtime.RaceWriteRange(unsafe.Pointer(&b[0]), len(b))
    33  		}
    34  	}
    35  	if b := m.OOB; len(b) > 0 {
    36  		runtime.RaceWriteRange(unsafe.Pointer(&b[0]), len(b))
    37  	}
    38  }