From a01840bb2836fed9f1c47b4386cea2e4352f820a Mon Sep 17 00:00:00 2001 From: vizee Date: Sun, 7 Apr 2019 22:28:59 +0800 Subject: [PATCH] remove ProcPin/ProcUnpin; see golang/go#27539 --- asm_amd64.go | 5 ++++- asm_amd64.s | 12 +++++++++++- asm_amd64_test.go | 6 ++++++ hack/hack.go | 6 ------ hack/hack_amd64.s | 8 -------- hack/hack_test.go | 20 -------------------- 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/asm_amd64.go b/asm_amd64.go index b28161a..bab775c 100644 --- a/asm_amd64.go +++ b/asm_amd64.go @@ -11,7 +11,10 @@ func Scas64(addr *uint64, cnt int, v int) (ret int) // lock //go:noescape -func LockOr32(addr *uint32, val uint32) +func LockAnd32(addr *uint32, val uint32) (ret uint32) + +//go:noescape +func LockOr32(addr *uint32, val uint32) (ret uint32) //go:noescape func LockCmpxchg8(addr *byte, cmp byte, val byte) (ok bool) diff --git a/asm_amd64.s b/asm_amd64.s index 89b74bd..904fb24 100644 --- a/asm_amd64.s +++ b/asm_amd64.s @@ -26,12 +26,22 @@ found: MOVQ DX, ret+24(FP) RET +// func LockAnd32(addr *uint32, val uint32) uint32 +TEXT ·LockAnd32(SB), NOSPLIT, $0-20 + MOVQ addr+0(FP), BP + MOVL val+8(FP), AX + LOCK + ANDL AX, (BP) + MOVL AX, ret+16(FP) + RET + // func LockOr32(addr *uint32, val uint32) -TEXT ·LockOr32(SB), NOSPLIT, $0-12 +TEXT ·LockOr32(SB), NOSPLIT, $0-20 MOVQ addr+0(FP), BP MOVL val+8(FP), AX LOCK ORL AX, (BP) + MOVL AX, ret+16(FP) RET // func LockCmpxchg8(addr *byte, cmp byte, val byte) (ok bool) diff --git a/asm_amd64_test.go b/asm_amd64_test.go index 85d5b7f..1ee270c 100644 --- a/asm_amd64_test.go +++ b/asm_amd64_test.go @@ -19,6 +19,12 @@ func TestScas64(t *testing.T) { t.Log(Scas64(&arr[0], len(arr), 4)) } +func TestLockAnd32(t *testing.T) { + v := uint32(1) + LockAnd32(&v, 2) + t.Log(v) +} + func TestLockOr32(t *testing.T) { v := uint32(1) LockOr32(&v, 2) diff --git a/hack/hack.go b/hack/hack.go index 165eeb2..c91150c 100644 --- a/hack/hack.go +++ b/hack/hack.go @@ -2,10 +2,4 @@ package hack func TLS() uintptr -// runtime - -func ProcPin() int - -func ProcUnpin() - func Nanotime() int64 diff --git a/hack/hack_amd64.s b/hack/hack_amd64.s index 61d7880..3f92ee9 100644 --- a/hack/hack_amd64.s +++ b/hack/hack_amd64.s @@ -5,14 +5,6 @@ TEXT ·TLS(SB), NOSPLIT, $8 MOVQ AX, ret+0(FP) RET -// func ProcPin() int -TEXT ·ProcPin(SB), NOSPLIT, $0 - JMP runtime·procPin(SB) - -// func ProcUnpin() -TEXT ·ProcUnpin(SB), NOSPLIT, $0 - JMP runtime·procUnpin(SB) - // func Nanotime() TEXT ·Nanotime(SB), NOSPLIT, $0 JMP runtime·nanotime(SB) diff --git a/hack/hack_test.go b/hack/hack_test.go index 43837ab..6eb3ea1 100644 --- a/hack/hack_test.go +++ b/hack/hack_test.go @@ -1,8 +1,6 @@ package hack import ( - "runtime" - "sync" "testing" ) @@ -10,24 +8,6 @@ func TestTLS(t *testing.T) { t.Log(TLS()) } -func TestProcPin(t *testing.T) { - if runtime.NumCPU() == 1 { - runtime.GOMAXPROCS(2) - } - - var wg sync.WaitGroup - for i := 0; i < 10; i++ { - wg.Add(1) - go func() { - n := ProcPin() - ProcUnpin() - t.Log(n) - wg.Done() - }() - } - wg.Wait() -} - func TestNanotime(t *testing.T) { t.Log(Nanotime()) }