race.go raw

   1  // Copyright 2015 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 race
   8  
   9  import (
  10  	"runtime"
  11  	"unsafe"
  12  )
  13  
  14  func ReadSlice[T any](s []T) {
  15  	if len(s) == 0 {
  16  		return
  17  	}
  18  	runtime.RaceReadRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
  19  }
  20  
  21  func WriteSlice[T any](s []T) {
  22  	if len(s) == 0 {
  23  		return
  24  	}
  25  	runtime.RaceWriteRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
  26  }
  27