src/runtime/defs_freebsd.go | 5 +++++ src/runtime/defs_freebsd_386.go | 8 ++++++++ src/runtime/defs_freebsd_amd64.go | 8 ++++++++ src/runtime/defs_freebsd_arm.go | 8 ++++++++ src/runtime/os_freebsd.go | 16 ++++++++-------- src/runtime/sys_freebsd_amd64.s | 4 ++-- src/runtime/sys_freebsd_arm.s | 2 +- diff --git a/src/runtime/defs_freebsd.go b/src/runtime/defs_freebsd.go index 0253685aace7fc0bb8495066a491a51895a17324..3f2184d09198e1a8df6f6af70e6d5a8fd411f4fb 100644 --- a/src/runtime/defs_freebsd.go +++ b/src/runtime/defs_freebsd.go @@ -23,6 +23,7 @@ #include #include #include #include +#include #include #include #include @@ -48,6 +49,8 @@ SA_SIGINFO = C.SA_SIGINFO SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK + + CLOCK_MONOTONIC = C.CLOCK_MONOTONIC UMTX_OP_WAIT_UINT = C.UMTX_OP_WAIT_UINT UMTX_OP_WAIT_UINT_PRIVATE = C.UMTX_OP_WAIT_UINT_PRIVATE @@ -129,5 +132,7 @@ type Timespec C.struct_timespec type Timeval C.struct_timeval type Itimerval C.struct_itimerval + +type Umtx_time C.struct__umtx_time type Kevent C.struct_kevent diff --git a/src/runtime/defs_freebsd_386.go b/src/runtime/defs_freebsd_386.go index 6938c18736ff65034e434ebb673cd7b161e746d3..efcbeb7a8199fbcd0a0bea6f5d724332e120f7d0 100644 --- a/src/runtime/defs_freebsd_386.go +++ b/src/runtime/defs_freebsd_386.go @@ -24,6 +24,8 @@ _SA_SIGINFO = 0x40 _SA_RESTART = 0x2 _SA_ONSTACK = 0x1 + _CLOCK_MONOTONIC = 0x4 + _UMTX_OP_WAIT_UINT = 0xb _UMTX_OP_WAIT_UINT_PRIVATE = 0xf _UMTX_OP_WAKE = 0x3 @@ -201,6 +203,12 @@ type itimerval struct { it_interval timeval it_value timeval +} + +type umtx_time struct { + _timeout timespec + _flags uint32 + _clockid uint32 } type keventt struct { diff --git a/src/runtime/defs_freebsd_amd64.go b/src/runtime/defs_freebsd_amd64.go index de98e7a3c13485bf62158819a319dd0290f2a918..594f9575874238f2ce6777a95510d438d9b59e61 100644 --- a/src/runtime/defs_freebsd_amd64.go +++ b/src/runtime/defs_freebsd_amd64.go @@ -24,6 +24,8 @@ _SA_SIGINFO = 0x40 _SA_RESTART = 0x2 _SA_ONSTACK = 0x1 + _CLOCK_MONOTONIC = 0x4 + _UMTX_OP_WAIT_UINT = 0xb _UMTX_OP_WAIT_UINT_PRIVATE = 0xf _UMTX_OP_WAKE = 0x3 @@ -212,6 +214,12 @@ type itimerval struct { it_interval timeval it_value timeval +} + +type umtx_time struct { + _timeout timespec + _flags uint32 + _clockid uint32 } type keventt struct { diff --git a/src/runtime/defs_freebsd_arm.go b/src/runtime/defs_freebsd_arm.go index 744330f4b3e2bf83e14250ea9d27a52a665f9962..0e9a2e93c5a716d49f76c271b7e08f9ef7e24bdb 100644 --- a/src/runtime/defs_freebsd_arm.go +++ b/src/runtime/defs_freebsd_arm.go @@ -24,6 +24,8 @@ _SA_SIGINFO = 0x40 _SA_RESTART = 0x2 _SA_ONSTACK = 0x1 + _CLOCK_MONOTONIC = 0x4 + _UMTX_OP_WAIT_UINT = 0xb _UMTX_OP_WAIT_UINT_PRIVATE = 0xf _UMTX_OP_WAKE = 0x3 @@ -174,6 +176,12 @@ type itimerval struct { it_interval timeval it_value timeval +} + +type umtx_time struct { + _timeout timespec + _flags uint32 + _clockid uint32 } type keventt struct { diff --git a/src/runtime/os_freebsd.go b/src/runtime/os_freebsd.go index c187ee805f68d07b246732fd37afce5fccc9df54..0e09c60ecdea6eb203e67322d3cb1ea352e4c122 100644 --- a/src/runtime/os_freebsd.go +++ b/src/runtime/os_freebsd.go @@ -35,7 +35,7 @@ func raise(sig int32) func raiseproc(sig int32) //go:noescape -func sys_umtx_op(addr *uint32, mode int32, val uint32, ptr2, ts *timespec) int32 +func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uintptr, ut *umtx_time) int32 func osyield() @@ -70,14 +70,14 @@ }) } func futexsleep1(addr *uint32, val uint32, ns int64) { - var tsp *timespec + var utp *umtx_time if ns >= 0 { - var ts timespec - ts.tv_nsec = 0 - ts.set_sec(int64(timediv(ns, 1000000000, (*int32)(unsafe.Pointer(&ts.tv_nsec))))) - tsp = &ts + 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 } - ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, nil, tsp) + ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp) if ret >= 0 || ret == -_EINTR { return } @@ -87,7 +87,7 @@ } //go:nosplit func futexwakeup(addr *uint32, cnt uint32) { - ret := sys_umtx_op(addr, _UMTX_OP_WAKE_PRIVATE, cnt, nil, nil) + ret := sys_umtx_op(addr, _UMTX_OP_WAKE_PRIVATE, cnt, 0, nil) if ret >= 0 { return } diff --git a/src/runtime/sys_freebsd_amd64.s b/src/runtime/sys_freebsd_amd64.s index 9700117d0f2edf18c04205fe04871b51c9a65fa2..277e7f8b075362b2ea78c2ae63eb7240e5f47225 100644 --- a/src/runtime/sys_freebsd_amd64.s +++ b/src/runtime/sys_freebsd_amd64.s @@ -14,8 +14,8 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 MOVQ addr+0(FP), DI MOVL mode+8(FP), SI MOVL val+12(FP), DX - MOVQ ptr2+16(FP), R10 - MOVQ ts+24(FP), R8 + MOVQ uaddr1+16(FP), R10 + MOVQ ut+24(FP), R8 MOVL $454, AX SYSCALL MOVL AX, ret+32(FP) diff --git a/src/runtime/sys_freebsd_arm.s b/src/runtime/sys_freebsd_arm.s index e7dfb281d586c9e55634290904c91940a882dd01..3c5a5cbbb06c59de22f46787d48da7341d53a071 100644 --- a/src/runtime/sys_freebsd_arm.s +++ b/src/runtime/sys_freebsd_arm.s @@ -45,7 +45,7 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 MOVW addr+0(FP), R0 MOVW mode+4(FP), R1 MOVW val+8(FP), R2 - MOVW ptr2+12(FP), R3 + MOVW uaddr1+12(FP), R3 ADD $20, R13 // arg 5 is passed on stack MOVW $SYS__umtx_op, R7 SWI $0