]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert lfstack to Go
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Aug 2014 17:10:45 +0000 (21:10 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Aug 2014 17:10:45 +0000 (21:10 +0400)
It is called from Go only in tests.

LGTM=khr
R=golang-codereviews, khr
CC=golang-codereviews, rlh, rsc
https://golang.org/cl/125610043

src/pkg/runtime/export_test.go
src/pkg/runtime/lfstack.c [moved from src/pkg/runtime/lfstack.goc with 86% similarity]

index adbc1e99552f96eaf3749b343de21c967d43449f..4ca5a7354f191ac761a34f14a2ec4371af0f4d95 100644 (file)
@@ -6,6 +6,8 @@
 
 package runtime
 
+import "unsafe"
+
 var Fadd64 = fadd64
 var Fsub64 = fsub64
 var Fmul64 = fmul64
@@ -31,11 +33,28 @@ type LFNode struct {
        Pushcnt uintptr
 }
 
-func lfstackpush_go(head *uint64, node *LFNode)
-func lfstackpop_go(head *uint64) *LFNode
+var (
+       lfstackpush_m,
+       lfstackpop_m mFunction
+)
+
+func LFStackPush(head *uint64, node *LFNode) {
+       mp := acquirem()
+       mp.ptrarg[0] = unsafe.Pointer(head)
+       mp.ptrarg[1] = unsafe.Pointer(node)
+       onM(&lfstackpush_m)
+       releasem(mp)
+}
 
-var LFStackPush = lfstackpush_go
-var LFStackPop = lfstackpop_go
+func LFStackPop(head *uint64) *LFNode {
+       mp := acquirem()
+       mp.ptrarg[0] = unsafe.Pointer(head)
+       onM(&lfstackpop_m)
+       node := (*LFNode)(unsafe.Pointer(mp.ptrarg[0]))
+       mp.ptrarg[0] = nil
+       releasem(mp)
+       return node
+}
 
 type ParFor struct {
        body    *byte
similarity index 86%
rename from src/pkg/runtime/lfstack.goc
rename to src/pkg/runtime/lfstack.c
index f7b8effa07ad4ba71e3c49af58089f6c5f6a45b3..57e0af28299add03c54af1656dbd42e7a72e1e25 100644 (file)
@@ -3,8 +3,8 @@
 // license that can be found in the LICENSE file.
 
 // Lock-free stack.
+// The following code runs only on g0 stack.
 
-package runtime
 #include "runtime.h"
 #include "arch_GOARCH.h"
 
@@ -72,10 +72,16 @@ runtime·lfstackpop(uint64 *head)
        }
 }
 
-func lfstackpush_go(head *uint64, node *LFNode) {
-       runtime·lfstackpush(head, 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;
 }
 
-func lfstackpop_go(head *uint64) (node *LFNode) {
-       node = runtime·lfstackpop(head);
+void
+runtime·lfstackpop_m(void)
+{
+       g->m->ptrarg[0] = runtime·lfstackpop(g->m->ptrarg[0]);
 }