]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.garbage] runtime: simplifiy lfstack.c due to undiagnosed buffer corruption.
authorRick Hudson <rlh@golang.org>
Thu, 23 Oct 2014 19:51:17 +0000 (15:51 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 23 Oct 2014 19:51:17 +0000 (15:51 -0400)
The changes got rid of the problems we were seeing.
We suspect the pushcnt field has a race.

LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/159330043

src/runtime/lfstack.c
src/runtime/runtime.h

index 57e0af28299add03c54af1656dbd42e7a72e1e25..0ced839c2350fd760bec51f367408305bd962478 100644 (file)
@@ -46,7 +46,7 @@ runtime·lfstackpush(uint64 *head, LFNode *node)
        new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<<PTR_BITS);
        for(;;) {
                old = runtime·atomicload64(head);
-               node->next = (LFNode*)(uintptr)(old&PTR_MASK);
+               node->next = old;
                if(runtime·cas64(head, old, new))
                        break;
        }
@@ -55,19 +55,17 @@ runtime·lfstackpush(uint64 *head, LFNode *node)
 LFNode*
 runtime·lfstackpop(uint64 *head)
 {
-       LFNode *node, *node2;
-       uint64 old, new;
+       LFNode *node;
+       uint64 old, next;
 
        for(;;) {
                old = runtime·atomicload64(head);
                if(old == 0)
                        return nil;
                node = (LFNode*)(uintptr)(old&PTR_MASK);
-               node2 = runtime·atomicloadp(&node->next);
-               new = 0;
-               if(node2 != nil)
-                       new = (uint64)(uintptr)node2|(((uint64)node2->pushcnt&CNT_MASK)<<PTR_BITS);
-               if(runtime·cas64(head, old, new))
+               next = runtime·atomicload64(&node->next);
+
+               if(runtime·cas64(head, old, next))
                        return node;
        }
 }
index bea7737993b9c9ee9d4d37f188263d9892f391d1..37929c59cf88daa1f530e5fec6849cfd89859cfd 100644 (file)
@@ -573,7 +573,7 @@ enum {
 // Lock-free stack node.
 struct LFNode
 {
-       LFNode  *next;
+       uint64  next;
        uintptr pushcnt;
 };