}
}
-func hammerAddInt32(uval *uint32, count int) {
- val := (*int32)(unsafe.Pointer(uval))
+func hammerAddInt32(uaddr *uint32, count int) {
+ addr := (*int32)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
- AddInt32(val, 1)
+ AddInt32(addr, 1)
}
}
-func hammerAddUint32(val *uint32, count int) {
+func hammerAddUint32(addr *uint32, count int) {
for i := 0; i < count; i++ {
- AddUint32(val, 1)
+ AddUint32(addr, 1)
}
}
-func hammerAddUintptr32(uval *uint32, count int) {
+func hammerAddUintptr32(uaddr *uint32, count int) {
// only safe when uintptr is 32-bit.
// not called on 64-bit systems.
- val := (*uintptr)(unsafe.Pointer(uval))
+ addr := (*uintptr)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
- AddUintptr(val, 1)
+ AddUintptr(addr, 1)
}
}
-func hammerCompareAndSwapInt32(uval *uint32, count int) {
- val := (*int32)(unsafe.Pointer(uval))
+func hammerCompareAndSwapInt32(uaddr *uint32, count int) {
+ addr := (*int32)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapInt32(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapInt32(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapUint32(val *uint32, count int) {
+func hammerCompareAndSwapUint32(addr *uint32, count int) {
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapUint32(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapUint32(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapUintptr32(uval *uint32, count int) {
+func hammerCompareAndSwapUintptr32(uaddr *uint32, count int) {
// only safe when uintptr is 32-bit.
// not called on 64-bit systems.
- val := (*uintptr)(unsafe.Pointer(uval))
+ addr := (*uintptr)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapUintptr(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapUintptr(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapPointer32(uval *uint32, count int) {
+func hammerCompareAndSwapPointer32(uaddr *uint32, count int) {
// only safe when uintptr is 32-bit.
// not called on 64-bit systems.
- val := (*unsafe.Pointer)(unsafe.Pointer(uval))
+ addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapPointer(val, v, unsafe.Pointer(uintptr(v)+1)) {
+ v := *addr
+ if CompareAndSwapPointer(addr, v, unsafe.Pointer(uintptr(v)+1)) {
break
}
}
}
}
-func hammerAddInt64(uval *uint64, count int) {
- val := (*int64)(unsafe.Pointer(uval))
+func hammerAddInt64(uaddr *uint64, count int) {
+ addr := (*int64)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
- AddInt64(val, 1)
+ AddInt64(addr, 1)
}
}
-func hammerAddUint64(val *uint64, count int) {
+func hammerAddUint64(addr *uint64, count int) {
for i := 0; i < count; i++ {
- AddUint64(val, 1)
+ AddUint64(addr, 1)
}
}
-func hammerAddUintptr64(uval *uint64, count int) {
+func hammerAddUintptr64(uaddr *uint64, count int) {
// only safe when uintptr is 64-bit.
// not called on 32-bit systems.
- val := (*uintptr)(unsafe.Pointer(uval))
+ addr := (*uintptr)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
- AddUintptr(val, 1)
+ AddUintptr(addr, 1)
}
}
-func hammerCompareAndSwapInt64(uval *uint64, count int) {
- val := (*int64)(unsafe.Pointer(uval))
+func hammerCompareAndSwapInt64(uaddr *uint64, count int) {
+ addr := (*int64)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapInt64(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapInt64(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapUint64(val *uint64, count int) {
+func hammerCompareAndSwapUint64(addr *uint64, count int) {
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapUint64(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapUint64(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapUintptr64(uval *uint64, count int) {
+func hammerCompareAndSwapUintptr64(uaddr *uint64, count int) {
// only safe when uintptr is 64-bit.
// not called on 32-bit systems.
- val := (*uintptr)(unsafe.Pointer(uval))
+ addr := (*uintptr)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapUintptr(val, v, v+1) {
+ v := *addr
+ if CompareAndSwapUintptr(addr, v, v+1) {
break
}
}
}
}
-func hammerCompareAndSwapPointer64(uval *uint64, count int) {
+func hammerCompareAndSwapPointer64(uaddr *uint64, count int) {
// only safe when uintptr is 64-bit.
// not called on 32-bit systems.
- val := (*unsafe.Pointer)(unsafe.Pointer(uval))
+ addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
for i := 0; i < count; i++ {
for {
- v := *val
- if CompareAndSwapPointer(val, v, unsafe.Pointer(uintptr(v)+1)) {
+ v := *addr
+ if CompareAndSwapPointer(addr, v, unsafe.Pointer(uintptr(v)+1)) {
break
}
}
}
}
-func hammerStoreLoadInt32(t *testing.T, valp unsafe.Pointer) {
- val := (*int32)(valp)
- v := LoadInt32(val)
+func hammerStoreLoadInt32(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*int32)(paddr)
+ v := LoadInt32(addr)
vlo := v & ((1 << 16) - 1)
vhi := v >> 16
if vlo != vhi {
if vlo == 1e4 {
new = 0
}
- StoreInt32(val, new)
+ StoreInt32(addr, new)
}
-func hammerStoreLoadUint32(t *testing.T, valp unsafe.Pointer) {
- val := (*uint32)(valp)
- v := LoadUint32(val)
+func hammerStoreLoadUint32(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*uint32)(paddr)
+ v := LoadUint32(addr)
vlo := v & ((1 << 16) - 1)
vhi := v >> 16
if vlo != vhi {
if vlo == 1e4 {
new = 0
}
- StoreUint32(val, new)
+ StoreUint32(addr, new)
}
-func hammerStoreLoadInt64(t *testing.T, valp unsafe.Pointer) {
- val := (*int64)(valp)
- v := LoadInt64(val)
+func hammerStoreLoadInt64(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*int64)(paddr)
+ v := LoadInt64(addr)
vlo := v & ((1 << 32) - 1)
vhi := v >> 32
if vlo != vhi {
t.Fatalf("Int64: %#x != %#x", vlo, vhi)
}
new := v + 1 + 1<<32
- StoreInt64(val, new)
+ StoreInt64(addr, new)
}
-func hammerStoreLoadUint64(t *testing.T, valp unsafe.Pointer) {
- val := (*uint64)(valp)
- v := LoadUint64(val)
+func hammerStoreLoadUint64(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*uint64)(paddr)
+ v := LoadUint64(addr)
vlo := v & ((1 << 32) - 1)
vhi := v >> 32
if vlo != vhi {
t.Fatalf("Uint64: %#x != %#x", vlo, vhi)
}
new := v + 1 + 1<<32
- StoreUint64(val, new)
+ StoreUint64(addr, new)
}
-func hammerStoreLoadUintptr(t *testing.T, valp unsafe.Pointer) {
- val := (*uintptr)(valp)
+func hammerStoreLoadUintptr(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*uintptr)(paddr)
var test64 uint64 = 1 << 50
arch32 := uintptr(test64) == 0
- v := LoadUintptr(val)
+ v := LoadUintptr(addr)
new := v
if arch32 {
vlo := v & ((1 << 16) - 1)
inc := uint64(1 + 1<<32)
new = v + uintptr(inc)
}
- StoreUintptr(val, new)
+ StoreUintptr(addr, new)
}
-func hammerStoreLoadPointer(t *testing.T, valp unsafe.Pointer) {
- val := (*unsafe.Pointer)(valp)
+func hammerStoreLoadPointer(t *testing.T, paddr unsafe.Pointer) {
+ addr := (*unsafe.Pointer)(paddr)
var test64 uint64 = 1 << 50
arch32 := uintptr(test64) == 0
- v := uintptr(LoadPointer(val))
+ v := uintptr(LoadPointer(addr))
new := v
if arch32 {
vlo := v & ((1 << 16) - 1)
inc := uint64(1 + 1<<32)
new = v + uintptr(inc)
}
- StorePointer(val, unsafe.Pointer(new))
+ StorePointer(addr, unsafe.Pointer(new))
}
func TestHammerStoreLoad(t *testing.T) {
// The compare-and-swap operation, implemented by the CompareAndSwapT
// functions, is the atomic equivalent of:
//
-// if *val == old {
-// *val = new
+// if *addr == old {
+// *addr = new
// return true
// }
// return false
//
+// The add operation, implemented by the AddT functions, is the atomic
+// equivalent of:
+//
+// *addr += delta
+// return *addr
+//
+// The load and store operations, implemented by the LoadT and StoreT
+// functions, are the atomic equivalents of "return *addr" and
+// "*addr = val".
+//
package atomic
import (
// On x86-32, the 64-bit functions use instructions unavailable before the Pentium MMX.
// CompareAndSwapInt32 executes the compare-and-swap operation for an int32 value.
-func CompareAndSwapInt32(val *int32, old, new int32) (swapped bool)
+func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)
// CompareAndSwapInt64 executes the compare-and-swap operation for an int64 value.
-func CompareAndSwapInt64(val *int64, old, new int64) (swapped bool)
+func CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)
// CompareAndSwapUint32 executes the compare-and-swap operation for a uint32 value.
-func CompareAndSwapUint32(val *uint32, old, new uint32) (swapped bool)
+func CompareAndSwapUint32(addr *uint32, old, new uint32) (swapped bool)
// CompareAndSwapUint64 executes the compare-and-swap operation for a uint64 value.
-func CompareAndSwapUint64(val *uint64, old, new uint64) (swapped bool)
+func CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)
// CompareAndSwapUintptr executes the compare-and-swap operation for a uintptr value.
-func CompareAndSwapUintptr(val *uintptr, old, new uintptr) (swapped bool)
+func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) (swapped bool)
// CompareAndSwapPointer executes the compare-and-swap operation for a unsafe.Pointer value.
-func CompareAndSwapPointer(val *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)
+func CompareAndSwapPointer(addr *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)
-// AddInt32 atomically adds delta to *val and returns the new value.
-func AddInt32(val *int32, delta int32) (new int32)
+// AddInt32 atomically adds delta to *addr and returns the new value.
+func AddInt32(addr *int32, delta int32) (new int32)
-// AddUint32 atomically adds delta to *val and returns the new value.
-func AddUint32(val *uint32, delta uint32) (new uint32)
+// AddUint32 atomically adds delta to *addr and returns the new value.
+func AddUint32(addr *uint32, delta uint32) (new uint32)
-// AddInt64 atomically adds delta to *val and returns the new value.
-func AddInt64(val *int64, delta int64) (new int64)
+// AddInt64 atomically adds delta to *addr and returns the new value.
+func AddInt64(addr *int64, delta int64) (new int64)
-// AddUint64 atomically adds delta to *val and returns the new value.
-func AddUint64(val *uint64, delta uint64) (new uint64)
+// AddUint64 atomically adds delta to *addr and returns the new value.
+func AddUint64(addr *uint64, delta uint64) (new uint64)
-// AddUintptr atomically adds delta to *val and returns the new value.
-func AddUintptr(val *uintptr, delta uintptr) (new uintptr)
+// AddUintptr atomically adds delta to *addr and returns the new value.
+func AddUintptr(addr *uintptr, delta uintptr) (new uintptr)
// LoadInt32 atomically loads *addr.
func LoadInt32(addr *int32) (val int32)