mirror of
https://github.com/golang/go
synced 2024-11-20 08:04:42 -07:00
b2a950bb73
Rename "gothrow" to "throw" now that the C version of "throw" is no longer needed. This change is purely mechanical except in panic.go where the old version of "throw" has been deleted. sed -i "" 's/[[:<:]]gothrow[[:>:]]/throw/g' runtime/*.go Change-Id: Icf0752299c35958b92870a97111c67bcd9159dc3 Reviewed-on: https://go-review.googlesource.com/2150 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net>
41 lines
934 B
Go
41 lines
934 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 "unsafe"
|
|
|
|
func lfstackpush(head *uint64, node *lfnode) {
|
|
node.pushcnt++
|
|
new := lfstackPack(node, node.pushcnt)
|
|
if node1, _ := lfstackUnpack(new); node1 != node {
|
|
println("runtime: lfstackpush invalid packing: node=", node, " cnt=", hex(node.pushcnt), " packed=", hex(new), " -> node=", node1, "\n")
|
|
throw("lfstackpush")
|
|
}
|
|
for {
|
|
old := atomicload64(head)
|
|
node.next = old
|
|
if cas64(head, old, new) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func lfstackpop(head *uint64) unsafe.Pointer {
|
|
for {
|
|
old := atomicload64(head)
|
|
if old == 0 {
|
|
return nil
|
|
}
|
|
node, _ := lfstackUnpack(old)
|
|
next := atomicload64(&node.next)
|
|
if cas64(head, old, next) {
|
|
return unsafe.Pointer(node)
|
|
}
|
|
}
|
|
}
|