race.go 511 B

1234567891011121314151617181920212223242526
  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. //go:build race
  5. package race
  6. import (
  7. "runtime"
  8. "unsafe"
  9. )
  10. func ReadSlice[T any](s []T) {
  11. if len(s) == 0 {
  12. return
  13. }
  14. runtime.RaceReadRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
  15. }
  16. func WriteSlice[T any](s []T) {
  17. if len(s) == 0 {
  18. return
  19. }
  20. runtime.RaceWriteRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
  21. }