Improve argument/return names for better docs (#96)
This change is a renaming with no functional changes. It includes the following renames: * `val` for arguments that replace the atomic value (e.g., `Store`). * `delta` for arguments that offset the atomic value (e.g., `Add`). * `old`, `new` for arguments to `CAS`. * `old` named return from `Swap`. * `swapped` for named return from `CAS`. This also matches the names used in the stdlib atomic interface: https://golang.org/pkg/sync/atomic/
This commit is contained in:
committed by
GitHub
parent
df5a5c3c08
commit
d8a8972198
@@ -28,10 +28,10 @@ import (
|
||||
//go:generate bin/gen-atomicwrapper -name=Float64 -type=float64 -wrapped=Uint64 -pack=math.Float64bits -unpack=math.Float64frombits -swap -json -imports math -file=float64.go
|
||||
|
||||
// Add atomically adds to the wrapped float64 and returns the new value.
|
||||
func (f *Float64) Add(s float64) float64 {
|
||||
func (f *Float64) Add(delta float64) float64 {
|
||||
for {
|
||||
old := f.Load()
|
||||
new := old + s
|
||||
new := old + delta
|
||||
if f.CAS(old, new) {
|
||||
return new
|
||||
}
|
||||
@@ -39,8 +39,8 @@ func (f *Float64) Add(s float64) float64 {
|
||||
}
|
||||
|
||||
// Sub atomically subtracts from the wrapped float64 and returns the new value.
|
||||
func (f *Float64) Sub(s float64) float64 {
|
||||
return f.Add(-s)
|
||||
func (f *Float64) Sub(delta float64) float64 {
|
||||
return f.Add(-delta)
|
||||
}
|
||||
|
||||
// CAS is an atomic compare-and-swap for float64 values.
|
||||
@@ -58,8 +58,8 @@ func (f *Float64) Sub(s float64) float64 {
|
||||
// }
|
||||
//
|
||||
// If CAS did not match NaN to match, then the above would loop forever.
|
||||
func (x *Float64) CAS(o, n float64) bool {
|
||||
return x.v.CAS(math.Float64bits(o), math.Float64bits(n))
|
||||
func (x *Float64) CAS(old, new float64) (swapped bool) {
|
||||
return x.v.CAS(math.Float64bits(old), math.Float64bits(new))
|
||||
}
|
||||
|
||||
// String encodes the wrapped value as a string.
|
||||
|
||||
Reference in New Issue
Block a user