// 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. #include "runtime.h" #include "arch.h" #if __SIZEOF_POINTER__ == 8 // Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag. // So we use 17msb of pointers as ABA counter. # define PTR_BITS 47 #else # define PTR_BITS 32 #endif #define PTR_MASK ((1ull<pushcnt++; new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<next = (LFNode*)(uintptr)(old&PTR_MASK); if(runtime_cas64(head, old, new)) break; } } LFNode* runtime_lfstackpop(uint64 *head) { LFNode *node, *node2; uint64 old, new; 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)<