import "go.uber.org/atomic"
Package atomic provides simple wrappers around numerics to enforce atomic access.
Code:
// Uint32 is a thin wrapper around the primitive uint32 type. var atom atomic.Uint32 // The wrapper ensures that all operations are atomic. atom.Store(42) fmt.Println(atom.Inc()) fmt.Println(atom.CAS(43, 0)) fmt.Println(atom.Load())
Output:
43 true 0
bool.go bool_ext.go doc.go duration.go duration_ext.go error.go error_ext.go float64.go float64_ext.go gen.go int32.go int64.go nocmp.go string.go string_ext.go uint32.go uint64.go value.go
type Bool struct {
// contains filtered or unexported fields
}
Bool is an atomic type-safe wrapper for bool values.
NewBool creates a new Bool.
CAS is an atomic compare-and-swap for bool values.
Load atomically loads the wrapped bool.
MarshalJSON encodes the wrapped bool into JSON.
Store atomically stores the passed bool.
String encodes the wrapped value as a string.
Swap atomically stores the given bool and returns the old value.
Toggle atomically negates the Boolean and returns the previous value.
UnmarshalJSON decodes a bool from JSON.
type Duration struct {
// contains filtered or unexported fields
}
Duration is an atomic type-safe wrapper for time.Duration values.
NewDuration creates a new Duration.
Add atomically adds to the wrapped time.Duration and returns the new value.
CAS is an atomic compare-and-swap for time.Duration values.
Load atomically loads the wrapped time.Duration.
MarshalJSON encodes the wrapped time.Duration into JSON.
Store atomically stores the passed time.Duration.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped time.Duration and returns the new value.
Swap atomically stores the given time.Duration and returns the old value.
UnmarshalJSON decodes a time.Duration from JSON.
type Error struct {
// contains filtered or unexported fields
}
Error is an atomic type-safe wrapper for error values.
NewError creates a new Error.
Load atomically loads the wrapped error.
Store atomically stores the passed error.
type Float64 struct {
// contains filtered or unexported fields
}
Float64 is an atomic type-safe wrapper for float64 values.
NewFloat64 creates a new Float64.
Add atomically adds to the wrapped float64 and returns the new value.
CAS is an atomic compare-and-swap for float64 values.
Load atomically loads the wrapped float64.
MarshalJSON encodes the wrapped float64 into JSON.
Store atomically stores the passed float64.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped float64 and returns the new value.
UnmarshalJSON decodes a float64 from JSON.
type Int32 struct {
// contains filtered or unexported fields
}
Int32 is an atomic wrapper around int32.
NewInt32 creates a new Int32.
Add atomically adds to the wrapped int32 and returns the new value.
CAS is an atomic compare-and-swap.
Dec atomically decrements the wrapped int32 and returns the new value.
Inc atomically increments the wrapped int32 and returns the new value.
Load atomically loads the wrapped value.
MarshalJSON encodes the wrapped int32 into JSON.
Store atomically stores the passed value.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped int32 and returns the new value.
Swap atomically swaps the wrapped int32 and returns the old value.
UnmarshalJSON decodes JSON into the wrapped int32.
type Int64 struct {
// contains filtered or unexported fields
}
Int64 is an atomic wrapper around int64.
NewInt64 creates a new Int64.
Add atomically adds to the wrapped int64 and returns the new value.
CAS is an atomic compare-and-swap.
Dec atomically decrements the wrapped int64 and returns the new value.
Inc atomically increments the wrapped int64 and returns the new value.
Load atomically loads the wrapped value.
MarshalJSON encodes the wrapped int64 into JSON.
Store atomically stores the passed value.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped int64 and returns the new value.
Swap atomically swaps the wrapped int64 and returns the old value.
UnmarshalJSON decodes JSON into the wrapped int64.
type String struct {
// contains filtered or unexported fields
}
String is an atomic type-safe wrapper for string values.
NewString creates a new String.
Load atomically loads the wrapped string.
MarshalText encodes the wrapped string into a textual form.
This makes it encodable as JSON, YAML, XML, and more.
Store atomically stores the passed string.
String returns the wrapped value.
UnmarshalText decodes text and replaces the wrapped string with it.
This makes it decodable from JSON, YAML, XML, and more.
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an atomic wrapper around uint32.
NewUint32 creates a new Uint32.
Add atomically adds to the wrapped uint32 and returns the new value.
CAS is an atomic compare-and-swap.
Dec atomically decrements the wrapped uint32 and returns the new value.
Inc atomically increments the wrapped uint32 and returns the new value.
Load atomically loads the wrapped value.
MarshalJSON encodes the wrapped uint32 into JSON.
Store atomically stores the passed value.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped uint32 and returns the new value.
Swap atomically swaps the wrapped uint32 and returns the old value.
UnmarshalJSON decodes JSON into the wrapped uint32.
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 is an atomic wrapper around uint64.
NewUint64 creates a new Uint64.
Add atomically adds to the wrapped uint64 and returns the new value.
CAS is an atomic compare-and-swap.
Dec atomically decrements the wrapped uint64 and returns the new value.
Inc atomically increments the wrapped uint64 and returns the new value.
Load atomically loads the wrapped value.
MarshalJSON encodes the wrapped uint64 into JSON.
Store atomically stores the passed value.
String encodes the wrapped value as a string.
Sub atomically subtracts from the wrapped uint64 and returns the new value.
Swap atomically swaps the wrapped uint64 and returns the old value.
UnmarshalJSON decodes JSON into the wrapped uint64.
Value shadows the type of the same name from sync/atomic https://godoc.org/sync/atomic#Value
Package atomic imports 5 packages (graph) and is imported by 561 packages. Updated 2020-09-15. Refresh now. Tools for package owners.