Documentation ¶
Overview ¶
Package atomic provides simple wrappers around numerics to enforce atomic access.
Example ¶
package main import ( "fmt" "go.uber.org/atomic" ) func main() { // 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
Index ¶
- type Bool
- type Duration
- func (d *Duration) Add(n time.Duration) time.Duration
- func (x *Duration) CAS(o, n time.Duration) bool
- func (x *Duration) Load() time.Duration
- func (x *Duration) MarshalJSON() ([]byte, error)
- func (x *Duration) Store(v time.Duration)
- func (d *Duration) String() string
- func (d *Duration) Sub(n time.Duration) time.Duration
- func (x *Duration) Swap(o time.Duration) time.Duration
- func (x *Duration) UnmarshalJSON(b []byte) error
- type Error
- type Float64
- func (f *Float64) Add(s float64) float64
- func (x *Float64) CAS(o, n float64) bool
- func (x *Float64) Load() float64
- func (x *Float64) MarshalJSON() ([]byte, error)
- func (x *Float64) Store(v float64)
- func (f *Float64) String() string
- func (f *Float64) Sub(s float64) float64
- func (x *Float64) UnmarshalJSON(b []byte) error
- type Int32
- func (i *Int32) Add(n int32) int32
- func (i *Int32) CAS(old, new int32) bool
- func (i *Int32) Dec() int32
- func (i *Int32) Inc() int32
- func (i *Int32) Load() int32
- func (i *Int32) MarshalJSON() ([]byte, error)
- func (i *Int32) Store(n int32)
- func (i *Int32) String() string
- func (i *Int32) Sub(n int32) int32
- func (i *Int32) Swap(n int32) int32
- func (i *Int32) UnmarshalJSON(b []byte) error
- type Int64
- func (i *Int64) Add(n int64) int64
- func (i *Int64) CAS(old, new int64) bool
- func (i *Int64) Dec() int64
- func (i *Int64) Inc() int64
- func (i *Int64) Load() int64
- func (i *Int64) MarshalJSON() ([]byte, error)
- func (i *Int64) Store(n int64)
- func (i *Int64) String() string
- func (i *Int64) Sub(n int64) int64
- func (i *Int64) Swap(n int64) int64
- func (i *Int64) UnmarshalJSON(b []byte) error
- type String
- type Uint32
- func (i *Uint32) Add(n uint32) uint32
- func (i *Uint32) CAS(old, new uint32) bool
- func (i *Uint32) Dec() uint32
- func (i *Uint32) Inc() uint32
- func (i *Uint32) Load() uint32
- func (i *Uint32) MarshalJSON() ([]byte, error)
- func (i *Uint32) Store(n uint32)
- func (i *Uint32) String() string
- func (i *Uint32) Sub(n uint32) uint32
- func (i *Uint32) Swap(n uint32) uint32
- func (i *Uint32) UnmarshalJSON(b []byte) error
- type Uint64
- func (i *Uint64) Add(n uint64) uint64
- func (i *Uint64) CAS(old, new uint64) bool
- func (i *Uint64) Dec() uint64
- func (i *Uint64) Inc() uint64
- func (i *Uint64) Load() uint64
- func (i *Uint64) MarshalJSON() ([]byte, error)
- func (i *Uint64) Store(n uint64)
- func (i *Uint64) String() string
- func (i *Uint64) Sub(n uint64) uint64
- func (i *Uint64) Swap(n uint64) uint64
- func (i *Uint64) UnmarshalJSON(b []byte) error
- type Uintptr
- func (i *Uintptr) Add(n uintptr) uintptr
- func (i *Uintptr) CAS(old, new uintptr) bool
- func (i *Uintptr) Dec() uintptr
- func (i *Uintptr) Inc() uintptr
- func (i *Uintptr) Load() uintptr
- func (i *Uintptr) MarshalJSON() ([]byte, error)
- func (i *Uintptr) Store(n uintptr)
- func (i *Uintptr) String() string
- func (i *Uintptr) Sub(n uintptr) uintptr
- func (i *Uintptr) Swap(n uintptr) uintptr
- func (i *Uintptr) UnmarshalJSON(b []byte) error
- type UnsafePointer
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is an atomic type-safe wrapper for bool values.
func (*Bool) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped bool into JSON.
func (*Bool) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes a bool from JSON.
type Duration ¶ added in v1.3.2
type Duration struct {
// contains filtered or unexported fields
}
Duration is an atomic type-safe wrapper for time.Duration values.
func NewDuration ¶ added in v1.3.2
NewDuration creates a new Duration.
func (*Duration) Add ¶ added in v1.3.2
Add atomically adds to the wrapped time.Duration and returns the new value.
func (*Duration) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped time.Duration into JSON.
func (*Duration) Sub ¶ added in v1.3.2
Sub atomically subtracts from the wrapped time.Duration and returns the new value.
func (*Duration) Swap ¶ added in v1.3.2
Swap atomically stores the given time.Duration and returns the old value.
func (*Duration) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes a time.Duration from JSON.
type Error ¶ added in v1.4.0
type Error struct {
// contains filtered or unexported fields
}
Error is an atomic type-safe wrapper for error values.
type Float64 ¶ added in v1.1.0
type Float64 struct {
// contains filtered or unexported fields
}
Float64 is an atomic type-safe wrapper for float64 values.
func NewFloat64 ¶ added in v1.1.0
NewFloat64 creates a new Float64.
func (*Float64) Add ¶ added in v1.1.0
Add atomically adds to the wrapped float64 and returns the new value.
func (*Float64) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped float64 into JSON.
func (*Float64) Sub ¶ added in v1.1.0
Sub atomically subtracts from the wrapped float64 and returns the new value.
func (*Float64) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes a float64 from JSON.
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 is an atomic wrapper around int32.
func (*Int32) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped int32 into JSON.
func (*Int32) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes JSON into the wrapped int32.
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 is an atomic wrapper around int64.
func (*Int64) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped int64 into JSON.
func (*Int64) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes JSON into the wrapped int64.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an atomic type-safe wrapper for string values.
func (*String) MarshalText ¶ added in v1.7.0
MarshalText encodes the wrapped string into a textual form.
This makes it encodable as JSON, YAML, XML, and more.
func (*String) UnmarshalText ¶ added in v1.7.0
UnmarshalText decodes text and replaces the wrapped string with it.
This makes it decodable from JSON, YAML, XML, and more.
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an atomic wrapper around uint32.
func (*Uint32) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped uint32 into JSON.
func (*Uint32) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes JSON into the wrapped uint32.
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 is an atomic wrapper around uint64.
func (*Uint64) MarshalJSON ¶ added in v1.7.0
MarshalJSON encodes the wrapped uint64 into JSON.
func (*Uint64) UnmarshalJSON ¶ added in v1.7.0
UnmarshalJSON decodes JSON into the wrapped uint64.
type Uintptr ¶ added in v1.8.0
type Uintptr struct {
// contains filtered or unexported fields
}
Uintptr is an atomic wrapper around uintptr.
func NewUintptr ¶ added in v1.8.0
NewUintptr creates a new Uintptr.
func (*Uintptr) Add ¶ added in v1.8.0
Add atomically adds to the wrapped uintptr and returns the new value.
func (*Uintptr) Dec ¶ added in v1.8.0
Dec atomically decrements the wrapped uintptr and returns the new value.
func (*Uintptr) Inc ¶ added in v1.8.0
Inc atomically increments the wrapped uintptr and returns the new value.
func (*Uintptr) MarshalJSON ¶ added in v1.8.0
MarshalJSON encodes the wrapped uintptr into JSON.
func (*Uintptr) Sub ¶ added in v1.8.0
Sub atomically subtracts from the wrapped uintptr and returns the new value.
func (*Uintptr) Swap ¶ added in v1.8.0
Swap atomically swaps the wrapped uintptr and returns the old value.
func (*Uintptr) UnmarshalJSON ¶ added in v1.8.0
UnmarshalJSON decodes JSON into the wrapped uintptr.
type UnsafePointer ¶ added in v1.8.0
type UnsafePointer struct {
// contains filtered or unexported fields
}
UnsafePointer is an atomic wrapper around unsafe.Pointer.
func NewUnsafePointer ¶ added in v1.8.0
func NewUnsafePointer(p unsafe.Pointer) *UnsafePointer
NewUnsafePointer creates a new UnsafePointer.
func (*UnsafePointer) CAS ¶ added in v1.8.0
func (p *UnsafePointer) CAS(old, new unsafe.Pointer) bool
CAS is an atomic compare-and-swap.
func (*UnsafePointer) Load ¶ added in v1.8.0
func (p *UnsafePointer) Load() unsafe.Pointer
Load atomically loads the wrapped value.
func (*UnsafePointer) Store ¶ added in v1.8.0
func (p *UnsafePointer) Store(q unsafe.Pointer)
Store atomically stores the passed value.
type Value ¶ added in v1.2.0
Value shadows the type of the same name from sync/atomic https://godoc.org/sync/atomic#Value
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
gen-atomicint
gen-atomicint generates an atomic wrapper around an integer type.
|
gen-atomicint generates an atomic wrapper around an integer type. |
gen-atomicwrapper
gen-atomicwrapper generates wrapper types around other atomic types.
|
gen-atomicwrapper generates wrapper types around other atomic types. |