diff options
| author | Michael Matloob <matloob@golang.org> | 2015-11-02 14:09:24 -0500 |
|---|---|---|
| committer | Michael Matloob <matloob@golang.org> | 2015-11-10 17:38:04 +0000 |
| commit | 67faca7d9c54b367aee5fdeef2d5dd609fcf99d0 (patch) | |
| tree | 5c6e8b4e243286311bbc4743d6a8e86f16dda85f /src/runtime/mcentral.go | |
| parent | d33360571f46b46724b908a5603520dce1e8a81c (diff) | |
| download | go-67faca7d9c54b367aee5fdeef2d5dd609fcf99d0.tar.xz | |
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 <matloob@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/mcentral.go')
| -rw-r--r-- | src/runtime/mcentral.go | 10 |
1 files changed, 6 insertions, 4 deletions
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) |
