]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/lfstack.go
[dev.garbage] runtime: Stop running gs during the GCscan phase.
[gostls13.git] / src / runtime / lfstack.go
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Lock-free stack.
6 // The following code runs only on g0 stack.
7
8 package runtime
9
10 import "unsafe"
11
12 func lfstackpush(head *uint64, node *lfnode) {
13         node.pushcnt++
14         new := lfstackPack(node, node.pushcnt)
15         for {
16                 old := atomicload64(head)
17                 node.next = old
18                 if cas64(head, old, new) {
19                         break
20                 }
21         }
22 }
23
24 func lfstackpop(head *uint64) unsafe.Pointer {
25         for {
26                 old := atomicload64(head)
27                 if old == 0 {
28                         return nil
29                 }
30                 node, _ := lfstackUnpack(old)
31                 next := atomicload64(&node.next)
32                 if cas64(head, old, next) {
33                         return unsafe.Pointer(node)
34                 }
35         }
36 }