mirror of
https://github.com/golang/go
synced 2024-11-20 00:34:43 -07:00
9cc9e95b28
This broke solaris, which apparently does use the upper 17 bits of the address space.
This reverts commit 3b02c5b1b6
.
Change-Id: Iedfe54abd0384960845468205f20191a97751c0b
Reviewed-on: https://go-review.googlesource.com/21652
Reviewed-by: Dave Cheney <dave@cheney.net>
44 lines
975 B
Go
44 lines
975 B
Go
// Copyright 2012 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.
|
|
|
|
// Lock-free stack.
|
|
// The following code runs only on g0 stack.
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"runtime/internal/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
func lfstackpush(head *uint64, node *lfnode) {
|
|
node.pushcnt++
|
|
new := lfstackPack(node, node.pushcnt)
|
|
if node1 := lfstackUnpack(new); node1 != node {
|
|
print("runtime: lfstackpush invalid packing: node=", node, " cnt=", hex(node.pushcnt), " packed=", hex(new), " -> node=", node1, "\n")
|
|
throw("lfstackpush")
|
|
}
|
|
for {
|
|
old := atomic.Load64(head)
|
|
node.next = old
|
|
if atomic.Cas64(head, old, new) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func lfstackpop(head *uint64) unsafe.Pointer {
|
|
for {
|
|
old := atomic.Load64(head)
|
|
if old == 0 {
|
|
return nil
|
|
}
|
|
node := lfstackUnpack(old)
|
|
next := atomic.Load64(&node.next)
|
|
if atomic.Cas64(head, old, next) {
|
|
return unsafe.Pointer(node)
|
|
}
|
|
}
|
|
}
|