race.go 907 B

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