[dev.cc] runtime: fix lfstack for amd64 addresses in top half of addr space
While we are here, add the linux/power64 version.
LGTM=austin
R=austin
CC=aram, dvyukov, golang-codereviews
https://golang.org/cl/177750043
diff --git a/src/runtime/lfstack.go b/src/runtime/lfstack.go
index c5dc94f..4a20fff 100644
--- a/src/runtime/lfstack.go
+++ b/src/runtime/lfstack.go
@@ -9,23 +9,12 @@
import "unsafe"
-const (
- // lfPtrBits and lfCountMask are defined in lfstack_*.go.
- lfPtrMask = 1<<lfPtrBits - 1
-)
-
func lfstackpush(head *uint64, node *lfnode) {
- unode := uintptr(unsafe.Pointer(node))
- if unode&^lfPtrMask != 0 {
- print("p=", node, "\n")
- gothrow("lfstackpush: invalid pointer")
- }
-
node.pushcnt++
- new := uint64(unode) | (uint64(node.pushcnt)&lfCountMask)<<lfPtrBits
+ new := lfstackPack(node, node.pushcnt)
for {
old := atomicload64(head)
- node.next = (*lfnode)(unsafe.Pointer(uintptr(old & lfPtrMask)))
+ node.next, _ = lfstackUnpack(old)
if cas64(head, old, new) {
break
}
@@ -38,11 +27,11 @@
if old == 0 {
return nil
}
- node := (*lfnode)(unsafe.Pointer(uintptr(old & lfPtrMask)))
+ node, _ := lfstackUnpack(old)
node2 := (*lfnode)(atomicloadp(unsafe.Pointer(&node.next)))
new := uint64(0)
if node2 != nil {
- new = uint64(uintptr(unsafe.Pointer(node2))) | uint64(node2.pushcnt&lfCountMask)<<lfPtrBits
+ new = lfstackPack(node2, node2.pushcnt)
}
if cas64(head, old, new) {
return unsafe.Pointer(node)