aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/lfstack.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-11-14 12:55:23 -0500
committerRuss Cox <rsc@golang.org>2014-11-14 12:55:23 -0500
commit5fce15a2a3cd94427bb9979d73acf14013ec7f31 (patch)
treea49b9ffa5eac49d991e820b27da919aadd9e010b /src/runtime/lfstack.go
parenta87e4a2d01097c7f2430df0427aaae9c0b6f2031 (diff)
downloadgo-5fce15a2a3cd94427bb9979d73acf14013ec7f31.tar.xz
[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
Diffstat (limited to 'src/runtime/lfstack.go')
-rw-r--r--src/runtime/lfstack.go19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/runtime/lfstack.go b/src/runtime/lfstack.go
index c5dc94f073..4a20fff9d8 100644
--- a/src/runtime/lfstack.go
+++ b/src/runtime/lfstack.go
@@ -9,23 +9,12 @@ package runtime
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 @@ func lfstackpop(head *uint64) unsafe.Pointer {
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)