mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.garbage] all: merge dev.cc into dev.garbage
The garbage collector is now written in Go. There is plenty to clean up (just like on dev.cc). all.bash passes on darwin/amd64, darwin/386, linux/amd64, linux/386. TBR=rlh R=austin, rlh, bradfitz CC=golang-codereviews https://golang.org/cl/173250043
This commit is contained in:
commit
0fcf54b3d2
384 changed files with 22419 additions and 69497 deletions
36
src/runtime/lfstack.go
Normal file
36
src/runtime/lfstack.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// 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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue