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/sigqueue.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/runtime/sigqueue.go') diff --git a/src/runtime/sigqueue.go b/src/runtime/sigqueue.go index f28067f3f9..8c9951ae1d 100644 --- a/src/runtime/sigqueue.go +++ b/src/runtime/sigqueue.go @@ -28,7 +28,10 @@ package runtime -import "unsafe" +import ( + "runtime/internal/atomic" + "unsafe" +) var sig struct { note note @@ -59,7 +62,7 @@ func sigsend(s uint32) bool { if mask&bit != 0 { return true // signal already in queue } - if cas(&sig.mask[s/32], mask, mask|bit) { + if atomic.Cas(&sig.mask[s/32], mask, mask|bit) { break } } @@ -67,18 +70,18 @@ func sigsend(s uint32) bool { // Notify receiver that queue has new bit. Send: for { - switch atomicload(&sig.state) { + switch atomic.Load(&sig.state) { default: throw("sigsend: inconsistent state") case sigIdle: - if cas(&sig.state, sigIdle, sigSending) { + if atomic.Cas(&sig.state, sigIdle, sigSending) { break Send } case sigSending: // notification already pending break Send case sigReceiving: - if cas(&sig.state, sigReceiving, sigIdle) { + if atomic.Cas(&sig.state, sigReceiving, sigIdle) { notewakeup(&sig.note) break Send } @@ -104,17 +107,17 @@ func signal_recv() uint32 { // Wait for updates to be available from signal sender. Receive: for { - switch atomicload(&sig.state) { + switch atomic.Load(&sig.state) { default: throw("signal_recv: inconsistent state") case sigIdle: - if cas(&sig.state, sigIdle, sigReceiving) { + if atomic.Cas(&sig.state, sigIdle, sigReceiving) { notetsleepg(&sig.note, -1) noteclear(&sig.note) break Receive } case sigSending: - if cas(&sig.state, sigSending, sigIdle) { + if atomic.Cas(&sig.state, sigSending, sigIdle) { break Receive } } @@ -122,7 +125,7 @@ func signal_recv() uint32 { // Incorporate updates from sender into local copy. for i := range sig.mask { - sig.recv[i] = xchg(&sig.mask[i], 0) + sig.recv[i] = atomic.Xchg(&sig.mask[i], 0) } } } -- cgit v1.3