| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| •6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package sync |
| 18 |
|
| 19 |
import ( |
| 20 |
"fmt" |
| 21 |
"reflect" |
| 22 |
"unsafe" |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
func Gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int) { |
| 32 |
gopark(unlockf, lock, reason, traceEv, traceskip) |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
func gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int) |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
func Goready(gp uintptr, traceskip int) { |
| 42 |
goready(gp, traceskip) |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
func goready(gp uintptr, traceskip int) |
| 47 |
|
| 48 |
|
| 49 |
const ( |
| 50 |
WaitReasonSelect uint8 = 9 |
| 51 |
WaitReasonChanReceive uint8 = 14 |
| 52 |
WaitReasonSemacquire uint8 = 18 |
| 53 |
) |
| 54 |
|
| 55 |
|
| 56 |
const ( |
| 57 |
TraceEvGoBlockRecv byte = 23 |
| 58 |
TraceEvGoBlockSelect byte = 24 |
| 59 |
TraceEvGoBlockSync byte = 25 |
| 60 |
) |
| 61 |
|
| 62 |
|
| 63 |
func Rand32() uint32 { |
| 64 |
return fastrand() |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
func Rand64() uint64 { |
| 69 |
return uint64(fastrand())<<32 | uint64(fastrand()) |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
func fastrand() uint32 |
| 74 |
|
| 75 |
|
| 76 |
func RandUintptr() uintptr { |
| 77 |
if unsafe.Sizeof(uintptr(0)) == 4 { |
| 78 |
return uintptr(Rand32()) |
| 79 |
} |
| 80 |
return uintptr(Rand64()) |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
func MapKeyHasher(m interface{}) func(unsafe.Pointer, uintptr) uintptr { |
| 87 |
if rtyp := reflect.TypeOf(m); rtyp.Kind() != reflect.Map { |
| 88 |
panic(fmt.Sprintf("sync.MapKeyHasher: m is %v, not map", rtyp)) |
| 89 |
} |
| 90 |
mtyp := *(**maptype)(unsafe.Pointer(&m)) |
| 91 |
return mtyp.hasher |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
type maptype struct { |
| 96 |
size uintptr |
| 97 |
ptrdata uintptr |
| 98 |
hash uint32 |
| 99 |
tflag uint8 |
| 100 |
align uint8 |
| 101 |
fieldAlign uint8 |
| 102 |
kind uint8 |
| 103 |
equal func(unsafe.Pointer, unsafe.Pointer) bool |
| 104 |
gcdata *byte |
| 105 |
str int32 |
| 106 |
ptrToThis int32 |
| 107 |
key unsafe.Pointer |
| 108 |
elem unsafe.Pointer |
| 109 |
bucket unsafe.Pointer |
| 110 |
hasher func(unsafe.Pointer, uintptr) uintptr |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
func semacquire(addr *uint32) |
| 118 |
|
| 119 |
|
| 120 |
func semrelease(addr *uint32, handoff bool, skipframes int) |
| 121 |
|
| 122 |
|
| 123 |
func canSpin(i int) bool |
| 124 |
|
| 125 |
|
| 126 |
func doSpin() |