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/internal/atomic/atomic_386.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/internal/atomic/atomic_386.go')
| -rw-r--r-- | src/runtime/internal/atomic/atomic_386.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/runtime/internal/atomic/atomic_386.go b/src/runtime/internal/atomic/atomic_386.go new file mode 100644 index 0000000000..ae7b58325a --- /dev/null +++ b/src/runtime/internal/atomic/atomic_386.go @@ -0,0 +1,80 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build 386 + +package atomic + +import "unsafe" + +// The calls to nop are to keep these functions from being inlined. +// If they are inlined we have no guarantee that later rewrites of the +// code by optimizers will preserve the relative order of memory accesses. + +//go:nosplit +func Load(ptr *uint32) uint32 { + nop() + return *ptr +} + +//go:nosplit +func Loadp(ptr unsafe.Pointer) unsafe.Pointer { + nop() + return *(*unsafe.Pointer)(ptr) +} + +//go:nosplit +func Xadd64(ptr *uint64, delta int64) uint64 { + for { + old := *ptr + if Cas64(ptr, old, old+uint64(delta)) { + return old + uint64(delta) + } + } +} + +//go:noescape +func Xadduintptr(ptr *uintptr, delta uintptr) uintptr + +//go:nosplit +func Xchg64(ptr *uint64, new uint64) uint64 { + for { + old := *ptr + if Cas64(ptr, old, new) { + return old + } + } +} + +//go:noescape +func Xadd(ptr *uint32, delta int32) uint32 + +//go:noescape +func Xchg(ptr *uint32, new uint32) uint32 + +//go:noescape +func Xchguintptr(ptr *uintptr, new uintptr) uintptr + +//go:noescape +func Load64(ptr *uint64) uint64 + +//go:noescape +func And8(ptr *uint8, val uint8) + +//go:noescape +func Or8(ptr *uint8, val uint8) + +// NOTE: Do not add atomicxor8 (XOR is not idempotent). + +//go:noescape +func Cas64(ptr *uint64, old, new uint64) bool + +//go:noescape +func Store(ptr *uint32, val uint32) + +//go:noescape +func Store64(ptr *uint64, val uint64) + +// NO go:noescape annotation; see atomic_pointer.go. +func Storep1(ptr unsafe.Pointer, val unsafe.Pointer) |
