-
Notifications
You must be signed in to change notification settings - Fork 249
/
race.go
61 lines (52 loc) · 1.13 KB
/
race.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2024+ Klaus Post. See LICENSE for license
//go:build race
package reedsolomon
import (
"runtime"
"unsafe"
)
const raceEnabled = true
func raceReadSlice[T any](s []T) {
if len(s) == 0 {
return
}
runtime.RaceReadRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
}
func raceWriteSlice[T any](s []T) {
if len(s) == 0 {
return
}
runtime.RaceWriteRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
}
func raceReadSlices[T any](s [][]T, start, n int) {
if len(s) == 0 {
return
}
runtime.RaceReadRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
for _, v := range s {
if len(v) == 0 {
continue
}
n := n
if n < 0 {
n = len(v) - start
}
runtime.RaceReadRange(unsafe.Pointer(&v[start]), n*int(unsafe.Sizeof(v[0])))
}
}
func raceWriteSlices[T any](s [][]T, start, n int) {
if len(s) == 0 {
return
}
runtime.RaceReadRange(unsafe.Pointer(&s[0]), len(s)*int(unsafe.Sizeof(s[0])))
for _, v := range s {
if len(v) == 0 {
continue
}
n := n
if n < 0 {
n = len(v) - start
}
runtime.RaceWriteRange(unsafe.Pointer(&v[start]), n*int(unsafe.Sizeof(v[0])))
}
}