race.go 891 B

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