1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:51:37 -07:00

runtime: convert openbsd/amd64 locking to libc

Switch openbsd/amd64 to locking via libc, rather than performing direct
system calls.

Update #36435

Change-Id: I5e92bd70ce557b78ff385577088a9775cc468ea9
Reviewed-on: https://go-review.googlesource.com/c/go/+/270378
Trust: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Joel Sing 2021-01-16 04:38:50 +11:00
parent 824f2d635c
commit 928bda4f4a
4 changed files with 71 additions and 26 deletions

View File

@ -46,14 +46,6 @@ func raiseproc(sig uint32)
func getthrid() int32
func thrkill(tid int32, sig int)
//go:noescape
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
//go:noescape
func thrwakeup(ident uintptr, n int32) int32
func osyield()
func kqueue() int32
//go:noescape

View File

@ -0,0 +1,15 @@
// 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.
// +build openbsd,!amd64
package runtime
//go:noescape
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
//go:noescape
func thrwakeup(ident uintptr, n int32) int32
func osyield()

View File

@ -0,0 +1,34 @@
// Copyright 2020 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.
// +build openbsd,amd64
package runtime
import "unsafe"
//go:nosplit
//go:cgo_unsafe_args
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 {
return libcCall(unsafe.Pointer(funcPC(thrsleep_trampoline)), unsafe.Pointer(&ident))
}
func thrsleep_trampoline()
//go:nosplit
//go:cgo_unsafe_args
func thrwakeup(ident uintptr, n int32) int32 {
return libcCall(unsafe.Pointer(funcPC(thrwakeup_trampoline)), unsafe.Pointer(&ident))
}
func thrwakeup_trampoline()
func osyield() {
libcCall(unsafe.Pointer(funcPC(sched_yield_trampoline)), unsafe.Pointer(nil))
}
func sched_yield_trampoline()
//go:cgo_import_dynamic libc_thrsleep __thrsleep "libc.so"
//go:cgo_import_dynamic libc_thrwakeup __thrwakeup "libc.so"
//go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so"
//go:cgo_import_dynamic _ _ "libc.so"

View File

@ -168,28 +168,32 @@ TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
POPQ BP
RET
TEXT runtime·osyield(SB),NOSPLIT,$0
MOVL $298, AX // sys_sched_yield
SYSCALL
TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 8(DI), SI // arg 2 - clock_id
MOVQ 16(DI), DX // arg 3 - abstime
MOVQ 24(DI), CX // arg 3 - lock
MOVQ 32(DI), R8 // arg 4 - abort
MOVQ 0(DI), DI // arg 1 - id
CALL libc_thrsleep(SB)
POPQ BP
RET
TEXT runtime·thrsleep(SB),NOSPLIT,$0
MOVQ ident+0(FP), DI // arg 1 - ident
MOVL clock_id+8(FP), SI // arg 2 - clock_id
MOVQ tsp+16(FP), DX // arg 3 - tp
MOVQ lock+24(FP), R10 // arg 4 - lock
MOVQ abort+32(FP), R8 // arg 5 - abort
MOVL $94, AX // sys___thrsleep
SYSCALL
MOVL AX, ret+40(FP)
TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 8(DI), SI // arg 2 - count
MOVQ 0(DI), DI // arg 1 - id
CALL libc_thrwakeup(SB)
POPQ BP
RET
TEXT runtime·thrwakeup(SB),NOSPLIT,$0
MOVQ ident+0(FP), DI // arg 1 - ident
MOVL n+8(FP), SI // arg 2 - n
MOVL $301, AX // sys___thrwakeup
SYSCALL
MOVL AX, ret+16(FP)
TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
CALL libc_sched_yield(SB)
POPQ BP
RET
// Exit the entire program (like C exit)