mirror of
https://github.com/golang/go
synced 2024-11-11 21:40:21 -07:00
sync/atomic: remove atomic pointer hammer tests
These depend on storing arbitrary integer values using pointer atomics, and we can't support that anymore. Change-Id: I8cadd6d462c3eebdbe7078f43fe7c779fa8f52b3 Reviewed-on: https://go-review.googlesource.com/2311 Reviewed-by: Rick Hudson <rlh@golang.org>
This commit is contained in:
parent
ccdb50931f
commit
813386f200
@ -759,14 +759,12 @@ var hammer32 = map[string]func(*uint32, int){
|
||||
"SwapInt32": hammerSwapInt32,
|
||||
"SwapUint32": hammerSwapUint32,
|
||||
"SwapUintptr": hammerSwapUintptr32,
|
||||
"SwapPointer": hammerSwapPointer32,
|
||||
"AddInt32": hammerAddInt32,
|
||||
"AddUint32": hammerAddUint32,
|
||||
"AddUintptr": hammerAddUintptr32,
|
||||
"CompareAndSwapInt32": hammerCompareAndSwapInt32,
|
||||
"CompareAndSwapUint32": hammerCompareAndSwapUint32,
|
||||
"CompareAndSwapUintptr": hammerCompareAndSwapUintptr32,
|
||||
"CompareAndSwapPointer": hammerCompareAndSwapPointer32,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -818,20 +816,6 @@ func hammerSwapUintptr32(uaddr *uint32, count int) {
|
||||
}
|
||||
}
|
||||
|
||||
func hammerSwapPointer32(uaddr *uint32, count int) {
|
||||
// only safe when uintptr is 32-bit.
|
||||
// not called on 64-bit systems.
|
||||
addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
|
||||
seed := int(uintptr(unsafe.Pointer(&count)))
|
||||
for i := 0; i < count; i++ {
|
||||
new := uintptr(seed+i)<<16 | uintptr(seed+i)<<16>>16
|
||||
old := uintptr(SwapPointer(addr, unsafe.Pointer(new)))
|
||||
if old>>16 != old<<16>>16 {
|
||||
panic(fmt.Sprintf("SwapPointer is not atomic: %#08x", old))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hammerAddInt32(uaddr *uint32, count int) {
|
||||
addr := (*int32)(unsafe.Pointer(uaddr))
|
||||
for i := 0; i < count; i++ {
|
||||
@ -891,20 +875,6 @@ func hammerCompareAndSwapUintptr32(uaddr *uint32, count int) {
|
||||
}
|
||||
}
|
||||
|
||||
func hammerCompareAndSwapPointer32(uaddr *uint32, count int) {
|
||||
// only safe when uintptr is 32-bit.
|
||||
// not called on 64-bit systems.
|
||||
addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
|
||||
for i := 0; i < count; i++ {
|
||||
for {
|
||||
v := LoadPointer(addr)
|
||||
if CompareAndSwapPointer(addr, v, unsafe.Pointer(uintptr(v)+1)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHammer32(t *testing.T) {
|
||||
const p = 4
|
||||
n := 100000
|
||||
@ -940,14 +910,12 @@ var hammer64 = map[string]func(*uint64, int){
|
||||
"SwapInt64": hammerSwapInt64,
|
||||
"SwapUint64": hammerSwapUint64,
|
||||
"SwapUintptr": hammerSwapUintptr64,
|
||||
"SwapPointer": hammerSwapPointer64,
|
||||
"AddInt64": hammerAddInt64,
|
||||
"AddUint64": hammerAddUint64,
|
||||
"AddUintptr": hammerAddUintptr64,
|
||||
"CompareAndSwapInt64": hammerCompareAndSwapInt64,
|
||||
"CompareAndSwapUint64": hammerCompareAndSwapUint64,
|
||||
"CompareAndSwapUintptr": hammerCompareAndSwapUintptr64,
|
||||
"CompareAndSwapPointer": hammerCompareAndSwapPointer64,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -999,20 +967,6 @@ func hammerSwapUintptr64(uaddr *uint64, count int) {
|
||||
}
|
||||
}
|
||||
|
||||
func hammerSwapPointer64(uaddr *uint64, count int) {
|
||||
// only safe when uintptr is 64-bit.
|
||||
// not called on 32-bit systems.
|
||||
addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
|
||||
seed := int(uintptr(unsafe.Pointer(&count)))
|
||||
for i := 0; i < count; i++ {
|
||||
new := uintptr(seed+i)<<32 | uintptr(seed+i)<<32>>32
|
||||
old := uintptr(SwapPointer(addr, unsafe.Pointer(new)))
|
||||
if old>>32 != old<<32>>32 {
|
||||
panic(fmt.Sprintf("SwapPointer is not atomic: %v", old))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hammerAddInt64(uaddr *uint64, count int) {
|
||||
addr := (*int64)(unsafe.Pointer(uaddr))
|
||||
for i := 0; i < count; i++ {
|
||||
@ -1072,20 +1026,6 @@ func hammerCompareAndSwapUintptr64(uaddr *uint64, count int) {
|
||||
}
|
||||
}
|
||||
|
||||
func hammerCompareAndSwapPointer64(uaddr *uint64, count int) {
|
||||
// only safe when uintptr is 64-bit.
|
||||
// not called on 32-bit systems.
|
||||
addr := (*unsafe.Pointer)(unsafe.Pointer(uaddr))
|
||||
for i := 0; i < count; i++ {
|
||||
for {
|
||||
v := LoadPointer(addr)
|
||||
if CompareAndSwapPointer(addr, v, unsafe.Pointer(uintptr(v)+1)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHammer64(t *testing.T) {
|
||||
if test64err != nil {
|
||||
t.Skipf("Skipping 64-bit tests: %v", test64err)
|
||||
|
Loading…
Reference in New Issue
Block a user