go.uber.org/atomic
Package atomic provides simple wrappers around numerics to enforce atomic access.
Package
Files: 17. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Vars
Types
Bool
Bool is an atomic type-safe wrapper for bool values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Duration
Duration is an atomic type-safe wrapper for time.Duration values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Error
Error is an atomic type-safe wrapper for error values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Float32
Float32 is an atomic type-safe wrapper for float32 values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Float64
Float64 is an atomic type-safe wrapper for float64 values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Int32
Int32 is an atomic wrapper around int32.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Int64
Int64 is an atomic wrapper around int64.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
String
String is an atomic type-safe wrapper for string values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Time
Time is an atomic type-safe wrapper for time.Time values.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Uint32
Uint32 is an atomic wrapper around uint32.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Uint64
Uint64 is an atomic wrapper around uint64.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Uintptr
Uintptr is an atomic wrapper around uintptr.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
UnsafePointer
UnsafePointer is an atomic wrapper around unsafe.Pointer.
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
| v |
|
No comment on field. |
Value
Value shadows the type of the same name from sync/atomic https://godoc.org/sync/atomic#Value
| Field name | Field type | Comment |
|---|---|---|
| _ |
|
No comment on field. |
|
No comment on field. |
nocmp
nocmp is an uncomparable struct. Embed this inside another struct to make it uncomparable.
type Foo struct {
nocmp
// ...
}
This DOES NOT:
- Disallow shallow copies of structs
- Disallow comparison of pointers to uncomparable structs
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
packedError
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| Value |
|
No comment on field. |
Functions
func NewBool
NewBool creates a new Bool.
func NewDuration
NewDuration creates a new Duration.
func NewError
NewError creates a new Error.
func NewFloat32
NewFloat32 creates a new Float32.
func NewFloat64
NewFloat64 creates a new Float64.
func NewInt32
NewInt32 creates a new Int32.
func NewInt64
NewInt64 creates a new Int64.
func NewString
NewString creates a new String.
func NewTime
NewTime creates a new Time.
func NewUint32
NewUint32 creates a new Uint32.
func NewUint64
NewUint64 creates a new Uint64.
func NewUintptr
NewUintptr creates a new Uintptr.
func NewUnsafePointer
NewUnsafePointer creates a new UnsafePointer.
func (*Bool) CAS
CAS is an atomic compare-and-swap for bool values.
Deprecated: Use CompareAndSwap.
func (*Bool) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for bool values.
func (*Bool) Load
Load atomically loads the wrapped bool.
func (*Bool) MarshalJSON
MarshalJSON encodes the wrapped bool into JSON.
Uses: json.Marshal.func (*Bool) Store
Store atomically stores the passed bool.
func (*Bool) String
String encodes the wrapped value as a string.
Uses: strconv.FormatBool.func (*Bool) Swap
Swap atomically stores the given bool and returns the old value.
func (*Bool) Toggle
Toggle atomically negates the Boolean and returns the previous value.
func (*Bool) UnmarshalJSON
UnmarshalJSON decodes a bool from JSON.
Uses: json.Unmarshal.func (*Duration) Add
Add atomically adds to the wrapped time.Duration and returns the new value.
Uses: time.Duration.func (*Duration) CAS
CAS is an atomic compare-and-swap for time.Duration values.
Deprecated: Use CompareAndSwap.
func (*Duration) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for time.Duration values.
func (*Duration) Load
Load atomically loads the wrapped time.Duration.
Uses: time.Duration.func (*Duration) MarshalJSON
MarshalJSON encodes the wrapped time.Duration into JSON.
Uses: json.Marshal.func (*Duration) Store
Store atomically stores the passed time.Duration.
func (*Duration) String
String encodes the wrapped value as a string.
func (*Duration) Sub
Sub atomically subtracts from the wrapped time.Duration and returns the new value.
Uses: time.Duration.func (*Duration) Swap
Swap atomically stores the given time.Duration and returns the old value.
Uses: time.Duration.func (*Duration) UnmarshalJSON
UnmarshalJSON decodes a time.Duration from JSON.
Uses: json.Unmarshal, time.Duration.func (*Error) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for error values.
func (*Error) Load
Load atomically loads the wrapped error.
func (*Error) Store
Store atomically stores the passed error.
func (*Error) Swap
Swap atomically stores the given error and returns the old value.
func (*Float32) Add
Add atomically adds to the wrapped float32 and returns the new value.
func (*Float32) CAS
CAS is an atomic compare-and-swap for float32 values.
Deprecated: Use CompareAndSwap
func (*Float32) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for float32 values.
Note: CompareAndSwap handles NaN incorrectly. NaN != NaN using Go's inbuilt operators but CompareAndSwap allows a stored NaN to compare equal to a passed in NaN. This avoids typical CompareAndSwap loops from blocking forever, e.g.,
for {
old := atom.Load()
new = f(old)
if atom.CompareAndSwap(old, new) {
break
}
}
If CompareAndSwap did not match NaN to match, then the above would loop forever.
Uses: math.Float32bits.func (*Float32) Load
Load atomically loads the wrapped float32.
Uses: math.Float32frombits.func (*Float32) MarshalJSON
MarshalJSON encodes the wrapped float32 into JSON.
Uses: json.Marshal.func (*Float32) Store
Store atomically stores the passed float32.
Uses: math.Float32bits.func (*Float32) String
String encodes the wrapped value as a string.
Uses: strconv.FormatFloat.func (*Float32) Sub
Sub atomically subtracts from the wrapped float32 and returns the new value.
func (*Float32) Swap
Swap atomically stores the given float32 and returns the old value.
Uses: math.Float32bits, math.Float32frombits.func (*Float32) UnmarshalJSON
UnmarshalJSON decodes a float32 from JSON.
Uses: json.Unmarshal.func (*Float64) Add
Add atomically adds to the wrapped float64 and returns the new value.
func (*Float64) CAS
CAS is an atomic compare-and-swap for float64 values.
Deprecated: Use CompareAndSwap
func (*Float64) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for float64 values.
Note: CompareAndSwap handles NaN incorrectly. NaN != NaN using Go's inbuilt operators but CompareAndSwap allows a stored NaN to compare equal to a passed in NaN. This avoids typical CompareAndSwap loops from blocking forever, e.g.,
for {
old := atom.Load()
new = f(old)
if atom.CompareAndSwap(old, new) {
break
}
}
If CompareAndSwap did not match NaN to match, then the above would loop forever.
Uses: math.Float64bits.func (*Float64) Load
Load atomically loads the wrapped float64.
Uses: math.Float64frombits.func (*Float64) MarshalJSON
MarshalJSON encodes the wrapped float64 into JSON.
Uses: json.Marshal.func (*Float64) Store
Store atomically stores the passed float64.
Uses: math.Float64bits.func (*Float64) String
String encodes the wrapped value as a string.
Uses: strconv.FormatFloat.func (*Float64) Sub
Sub atomically subtracts from the wrapped float64 and returns the new value.
func (*Float64) Swap
Swap atomically stores the given float64 and returns the old value.
Uses: math.Float64bits, math.Float64frombits.func (*Float64) UnmarshalJSON
UnmarshalJSON decodes a float64 from JSON.
Uses: json.Unmarshal.func (*Int32) Add
Add atomically adds to the wrapped int32 and returns the new value.
Uses: atomic.AddInt32.func (*Int32) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap.
func (*Int32) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapInt32.func (*Int32) Dec
Dec atomically decrements the wrapped int32 and returns the new value.
func (*Int32) Inc
Inc atomically increments the wrapped int32 and returns the new value.
func (*Int32) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadInt32.func (*Int32) MarshalJSON
MarshalJSON encodes the wrapped int32 into JSON.
Uses: json.Marshal.func (*Int32) Store
Store atomically stores the passed value.
Uses: atomic.StoreInt32.func (*Int32) String
String encodes the wrapped value as a string.
Uses: strconv.FormatInt.func (*Int32) Sub
Sub atomically subtracts from the wrapped int32 and returns the new value.
Uses: atomic.AddInt32.func (*Int32) Swap
Swap atomically swaps the wrapped int32 and returns the old value.
Uses: atomic.SwapInt32.func (*Int32) UnmarshalJSON
UnmarshalJSON decodes JSON into the wrapped int32.
Uses: json.Unmarshal.func (*Int64) Add
Add atomically adds to the wrapped int64 and returns the new value.
Uses: atomic.AddInt64.func (*Int64) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap.
func (*Int64) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapInt64.func (*Int64) Dec
Dec atomically decrements the wrapped int64 and returns the new value.
func (*Int64) Inc
Inc atomically increments the wrapped int64 and returns the new value.
func (*Int64) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadInt64.func (*Int64) MarshalJSON
MarshalJSON encodes the wrapped int64 into JSON.
Uses: json.Marshal.func (*Int64) Store
Store atomically stores the passed value.
Uses: atomic.StoreInt64.func (*Int64) String
String encodes the wrapped value as a string.
Uses: strconv.FormatInt.func (*Int64) Sub
Sub atomically subtracts from the wrapped int64 and returns the new value.
Uses: atomic.AddInt64.func (*Int64) Swap
Swap atomically swaps the wrapped int64 and returns the old value.
Uses: atomic.SwapInt64.func (*Int64) UnmarshalJSON
UnmarshalJSON decodes JSON into the wrapped int64.
Uses: json.Unmarshal.func (*String) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap for string values.
func (*String) Load
Load atomically loads the wrapped string.
func (*String) MarshalText
MarshalText encodes the wrapped string into a textual form.
This makes it encodable as JSON, YAML, XML, and more.
func (*String) Store
Store atomically stores the passed string.
func (*String) String
String returns the wrapped value.
func (*String) Swap
Swap atomically stores the given string and returns the old value.
func (*String) UnmarshalText
UnmarshalText decodes text and replaces the wrapped string with it.
This makes it decodable from JSON, YAML, XML, and more.
func (*Time) Load
Load atomically loads the wrapped time.Time.
func (*Time) Store
Store atomically stores the passed time.Time.
func (*Uint32) Add
Add atomically adds to the wrapped uint32 and returns the new value.
Uses: atomic.AddUint32.func (*Uint32) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap.
func (*Uint32) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapUint32.func (*Uint32) Dec
Dec atomically decrements the wrapped uint32 and returns the new value.
func (*Uint32) Inc
Inc atomically increments the wrapped uint32 and returns the new value.
func (*Uint32) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadUint32.func (*Uint32) MarshalJSON
MarshalJSON encodes the wrapped uint32 into JSON.
Uses: json.Marshal.func (*Uint32) Store
Store atomically stores the passed value.
Uses: atomic.StoreUint32.func (*Uint32) String
String encodes the wrapped value as a string.
Uses: strconv.FormatUint.func (*Uint32) Sub
Sub atomically subtracts from the wrapped uint32 and returns the new value.
Uses: atomic.AddUint32.func (*Uint32) Swap
Swap atomically swaps the wrapped uint32 and returns the old value.
Uses: atomic.SwapUint32.func (*Uint32) UnmarshalJSON
UnmarshalJSON decodes JSON into the wrapped uint32.
Uses: json.Unmarshal.func (*Uint64) Add
Add atomically adds to the wrapped uint64 and returns the new value.
Uses: atomic.AddUint64.func (*Uint64) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap.
func (*Uint64) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapUint64.func (*Uint64) Dec
Dec atomically decrements the wrapped uint64 and returns the new value.
func (*Uint64) Inc
Inc atomically increments the wrapped uint64 and returns the new value.
func (*Uint64) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadUint64.func (*Uint64) MarshalJSON
MarshalJSON encodes the wrapped uint64 into JSON.
Uses: json.Marshal.func (*Uint64) Store
Store atomically stores the passed value.
Uses: atomic.StoreUint64.func (*Uint64) String
String encodes the wrapped value as a string.
Uses: strconv.FormatUint.func (*Uint64) Sub
Sub atomically subtracts from the wrapped uint64 and returns the new value.
Uses: atomic.AddUint64.func (*Uint64) Swap
Swap atomically swaps the wrapped uint64 and returns the old value.
Uses: atomic.SwapUint64.func (*Uint64) UnmarshalJSON
UnmarshalJSON decodes JSON into the wrapped uint64.
Uses: json.Unmarshal.func (*Uintptr) Add
Add atomically adds to the wrapped uintptr and returns the new value.
Uses: atomic.AddUintptr.func (*Uintptr) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap.
func (*Uintptr) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapUintptr.func (*Uintptr) Dec
Dec atomically decrements the wrapped uintptr and returns the new value.
func (*Uintptr) Inc
Inc atomically increments the wrapped uintptr and returns the new value.
func (*Uintptr) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadUintptr.func (*Uintptr) MarshalJSON
MarshalJSON encodes the wrapped uintptr into JSON.
Uses: json.Marshal.func (*Uintptr) Store
Store atomically stores the passed value.
Uses: atomic.StoreUintptr.func (*Uintptr) String
String encodes the wrapped value as a string.
Uses: strconv.FormatUint.func (*Uintptr) Sub
Sub atomically subtracts from the wrapped uintptr and returns the new value.
Uses: atomic.AddUintptr.func (*Uintptr) Swap
Swap atomically swaps the wrapped uintptr and returns the old value.
Uses: atomic.SwapUintptr.func (*Uintptr) UnmarshalJSON
UnmarshalJSON decodes JSON into the wrapped uintptr.
Uses: json.Unmarshal.func (*UnsafePointer) CAS
CAS is an atomic compare-and-swap.
Deprecated: Use CompareAndSwap
func (*UnsafePointer) CompareAndSwap
CompareAndSwap is an atomic compare-and-swap.
Uses: atomic.CompareAndSwapPointer.func (*UnsafePointer) Load
Load atomically loads the wrapped value.
Uses: atomic.LoadPointer.func (*UnsafePointer) Store
Store atomically stores the passed value.
Uses: atomic.StorePointer.func (*UnsafePointer) Swap
Swap atomically swaps the wrapped unsafe.Pointer and returns the old value.
Uses: atomic.SwapPointer.Private functions
func boolToInt
func packError
func packString
func packTime
func truthy
func unpackError
func unpackString
func unpackTime
Tests
Files: 17. Third party imports: 2. Imports from organisation: 0. Tests: 31. Benchmarks: 1.