diff options
| author | Russ Cox <rsc@golang.org> | 2014-11-15 08:00:38 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-11-15 08:00:38 -0500 |
| commit | 0fcf54b3d2bc42a947c65e9a520d078b671f8432 (patch) | |
| tree | 071014526059897ceef47c43e5a24ddc0a57b636 /src/runtime/lfstack.c | |
| parent | 9ef4e5610809780555260f386d6e20f3df87c6ce (diff) | |
| parent | 5fce15a2a3cd94427bb9979d73acf14013ec7f31 (diff) | |
| download | go-0fcf54b3d2bc42a947c65e9a520d078b671f8432.tar.xz | |
[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
Diffstat (limited to 'src/runtime/lfstack.c')
| -rw-r--r-- | src/runtime/lfstack.c | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/runtime/lfstack.c b/src/runtime/lfstack.c deleted file mode 100644 index 0ced839c23..0000000000 --- a/src/runtime/lfstack.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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. - -#include "runtime.h" -#include "arch_GOARCH.h" - -#ifdef _64BIT -// 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<<PTR_BITS)-1) -#define CNT_MASK (0ull-1) - -#ifdef _64BIT -#ifdef GOOS_solaris -// SPARC64 and Solaris on AMD64 uses all 64 bits of virtual addresses. -// Use low-order three bits as ABA counter. -// http://docs.oracle.com/cd/E19120-01/open.solaris/816-5138/6mba6ua5p/index.html -#undef PTR_BITS -#undef CNT_MASK -#undef PTR_MASK -#define PTR_BITS 0 -#define CNT_MASK 7 -#define PTR_MASK ((0ull-1)<<3) -#endif -#endif - -void -runtime·lfstackpush(uint64 *head, LFNode *node) -{ - uint64 old, new; - - if((uintptr)node != ((uintptr)node&PTR_MASK)) { - runtime·printf("p=%p\n", node); - runtime·throw("runtime·lfstackpush: invalid pointer"); - } - - node->pushcnt++; - new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<<PTR_BITS); - for(;;) { - old = runtime·atomicload64(head); - node->next = old; - if(runtime·cas64(head, old, new)) - break; - } -} - -LFNode* -runtime·lfstackpop(uint64 *head) -{ - LFNode *node; - uint64 old, next; - - for(;;) { - old = runtime·atomicload64(head); - if(old == 0) - return nil; - node = (LFNode*)(uintptr)(old&PTR_MASK); - next = runtime·atomicload64(&node->next); - - if(runtime·cas64(head, old, next)) - return node; - } -} - -void -runtime·lfstackpush_m(void) -{ - runtime·lfstackpush(g->m->ptrarg[0], g->m->ptrarg[1]); - g->m->ptrarg[0] = nil; - g->m->ptrarg[1] = nil; -} - -void -runtime·lfstackpop_m(void) -{ - g->m->ptrarg[0] = runtime·lfstackpop(g->m->ptrarg[0]); -} |
