2016-09-30 15:45:08 +02:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2018-09-24 23:46:21 +02:00
|
|
|
type mOS struct{}
|
2016-09-30 15:45:08 +02:00
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
//extern _umtx_op
|
2017-01-14 01:05:42 +01:00
|
|
|
func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uinptr, ts *umtx_time) int32
|
2016-09-30 15:45:08 +02:00
|
|
|
|
2018-01-09 02:23:08 +01:00
|
|
|
func getPageSize() uintptr {
|
|
|
|
mib := [2]uint32{_CTL_HW, _HW_PAGESIZE}
|
|
|
|
out := uint32(0)
|
|
|
|
nout := unsafe.Sizeof(out)
|
|
|
|
ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
|
|
|
|
if ret >= 0 {
|
|
|
|
return uintptr(out)
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:45:08 +02:00
|
|
|
// FreeBSD's umtx_op syscall is effectively the same as Linux's futex, and
|
|
|
|
// thus the code is largely similar. See Linux implementation
|
|
|
|
// and lock_futex.go for comments.
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func futexsleep(addr *uint32, val uint32, ns int64) {
|
|
|
|
systemstack(func() {
|
|
|
|
futexsleep1(addr, val, ns)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func futexsleep1(addr *uint32, val uint32, ns int64) {
|
2017-01-14 01:05:42 +01:00
|
|
|
var utp *umtx_time
|
2016-09-30 15:45:08 +02:00
|
|
|
if ns >= 0 {
|
2017-01-14 01:05:42 +01:00
|
|
|
var ut umtx_time
|
|
|
|
ut._clockid = _CLOCK_MONOTONIC
|
|
|
|
ut._timeout.set_sec(int64(timediv(ns, 1000000000, (*int32)(unsafe.Pointer(&ut._timeout.tv_nsec)))))
|
|
|
|
utp = &ut
|
2016-09-30 15:45:08 +02:00
|
|
|
}
|
2017-01-14 01:05:42 +01:00
|
|
|
ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp)
|
2016-09-30 15:45:08 +02:00
|
|
|
if ret >= 0 || ret == -_EINTR {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
print("umtx_wait addr=", addr, " val=", val, " ret=", ret, "\n")
|
|
|
|
*(*int32)(unsafe.Pointer(uintptr(0x1005))) = 0x1005
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func futexwakeup(addr *uint32, cnt uint32) {
|
2017-01-14 01:05:42 +01:00
|
|
|
ret := sys_umtx_op(addr, _UMTX_OP_WAKE_PRIVATE, cnt, 0, nil)
|
2016-09-30 15:45:08 +02:00
|
|
|
if ret >= 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
systemstack(func() {
|
|
|
|
print("umtx_wake_addr=", addr, " ret=", ret, "\n")
|
|
|
|
})
|
|
|
|
}
|