From 67faca7d9c54b367aee5fdeef2d5dd609fcf99d0 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Mon, 2 Nov 2015 14:09:24 -0500 Subject: runtime: break atomics out into package runtime/internal/atomic This change breaks out most of the atomics functions in the runtime into package runtime/internal/atomic. It adds some basic support in the toolchain for runtime packages, and also modifies linux/arm atomics to remove the dependency on the runtime's mutex. The mutexes have been replaced with spinlocks. all trybots are happy! In addition to the trybots, I've tested on the darwin/arm64 builder, on the darwin/arm builder, and on a ppc64le machine. Change-Id: I6698c8e3cf3834f55ce5824059f44d00dc8e3c2f Reviewed-on: https://go-review.googlesource.com/14204 Run-TryBot: Michael Matloob Reviewed-by: Russ Cox --- src/runtime/mcentral.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/runtime/mcentral.go') diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go index 22c13e0568..1e1f6fd13d 100644 --- a/src/runtime/mcentral.go +++ b/src/runtime/mcentral.go @@ -12,6 +12,8 @@ package runtime +import "runtime/internal/atomic" + // Central list of free objects of a given size. type mcentral struct { lock mutex @@ -37,7 +39,7 @@ func mCentral_CacheSpan(c *mcentral) *mspan { retry: var s *mspan for s = c.nonempty.first; s != nil; s = s.next { - if s.sweepgen == sg-2 && cas(&s.sweepgen, sg-2, sg-1) { + if s.sweepgen == sg-2 && atomic.Cas(&s.sweepgen, sg-2, sg-1) { mSpanList_Remove(&c.nonempty, s) mSpanList_InsertBack(&c.empty, s) unlock(&c.lock) @@ -56,7 +58,7 @@ retry: } for s = c.empty.first; s != nil; s = s.next { - if s.sweepgen == sg-2 && cas(&s.sweepgen, sg-2, sg-1) { + if s.sweepgen == sg-2 && atomic.Cas(&s.sweepgen, sg-2, sg-1) { // we have an empty span that requires sweeping, // sweep it and see if we can free some space in it mSpanList_Remove(&c.empty, s) @@ -148,7 +150,7 @@ func mCentral_FreeSpan(c *mcentral, s *mspan, n int32, start gclinkptr, end gcli if !mSpan_InList(s) { throw("can't preserve unlinked span") } - atomicstore(&s.sweepgen, mheap_.sweepgen) + atomic.Store(&s.sweepgen, mheap_.sweepgen) return false } @@ -164,7 +166,7 @@ func mCentral_FreeSpan(c *mcentral, s *mspan, n int32, start gclinkptr, end gcli // the span may be used in an MCache, so it must come after the // linked list operations above (actually, just after the // lock of c above.) - atomicstore(&s.sweepgen, mheap_.sweepgen) + atomic.Store(&s.sweepgen, mheap_.sweepgen) if s.ref != 0 { unlock(&c.lock) -- cgit v1.3-5-g9baa