From ae875e040c6200c9bfae0df9f17d4620abc9e707 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 21 Aug 2014 21:10:45 +0400 Subject: [PATCH] runtime: convert lfstack to Go 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 | 27 ++++++++++++++++++---- src/pkg/runtime/{lfstack.goc => lfstack.c} | 16 +++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) rename src/pkg/runtime/{lfstack.goc => lfstack.c} (86%) diff --git a/src/pkg/runtime/export_test.go b/src/pkg/runtime/export_test.go index adbc1e9955..4ca5a7354f 100644 --- a/src/pkg/runtime/export_test.go +++ b/src/pkg/runtime/export_test.go @@ -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 diff --git a/src/pkg/runtime/lfstack.goc b/src/pkg/runtime/lfstack.c similarity index 86% rename from src/pkg/runtime/lfstack.goc rename to src/pkg/runtime/lfstack.c index f7b8effa07..57e0af2829 100644 --- a/src/pkg/runtime/lfstack.goc +++ b/src/pkg/runtime/lfstack.c @@ -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]); } -- 2.48.1