diff options
Diffstat (limited to 'src/runtime/lfstack.go')
| -rw-r--r-- | src/runtime/lfstack.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/runtime/lfstack.go b/src/runtime/lfstack.go index ea640eb12f..db54ecb05e 100644 --- a/src/runtime/lfstack.go +++ b/src/runtime/lfstack.go @@ -3,6 +3,9 @@ // license that can be found in the LICENSE file. // Lock-free stack. +// Initialize head to 0, compare with 0 to test for emptiness. +// The stack does not keep pointers to nodes, +// so they can be garbage collected if there are no other pointers to nodes. // The following code runs only on g0 stack. package runtime @@ -15,7 +18,7 @@ import ( func lfstackpush(head *uint64, node *lfnode) { node.pushcnt++ new := lfstackPack(node, node.pushcnt) - if node1, _ := lfstackUnpack(new); node1 != node { + 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") } @@ -34,7 +37,7 @@ func lfstackpop(head *uint64) unsafe.Pointer { if old == 0 { return nil } - node, _ := lfstackUnpack(old) + node := lfstackUnpack(old) next := atomic.Load64(&node.next) if atomic.Cas64(head, old, next) { return unsafe.Pointer(node) |
