Add CompareAndSwap and Swap, Deprecate CAS (#111)

Adds CompareAndSwap and Swap methods to String, Error, and Value,
implemented by making use of Value.CompareAndSwap and Value.Swap
added in Go 1.17.

Following that, add CompareAndSwap to all other types with "CAS" methods
and deprecate CAS in favor of CompareAndSwap, since that's the convention
the standard library chose for these in Go 1.19.
This commit is contained in:
eNV25
2022-08-06 22:12:19 +04:00
committed by GitHub
parent 01497d22b0
commit d4bbbc828d
18 changed files with 201 additions and 40 deletions

View File

@@ -66,7 +66,14 @@ func (i *Uintptr) Dec() uintptr {
}
// CAS is an atomic compare-and-swap.
//
// Deprecated: Use CompareAndSwap.
func (i *Uintptr) CAS(old, new uintptr) (swapped bool) {
return i.CompareAndSwap(old, new)
}
// CompareAndSwap is an atomic compare-and-swap.
func (i *Uintptr) CompareAndSwap(old, new uintptr) (swapped bool) {
return atomic.CompareAndSwapUintptr(&i.v, old, new)
}