Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/zxfonline/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)) bb, _ := atom.MarshalBinary() atom.UnmarshalBinary(bb) fmt.Println(atom.Load()) }
Output: 43 true 0
Index ¶
- Variables
- type Bool
- func (b *Bool) GobDecode(data []byte) error
- func (b *Bool) GobEncode() ([]byte, error)
- func (b *Bool) Load() bool
- func (b *Bool) MarshalBinary() ([]byte, error)
- func (b *Bool) MarshalJSON() ([]byte, error)
- func (b *Bool) MarshalText() ([]byte, error)
- func (b *Bool) Store(newz bool)
- func (b *Bool) Swap(newz bool) bool
- func (b *Bool) Toggle() bool
- func (b *Bool) UnmarshalBinary(data []byte) error
- func (b *Bool) UnmarshalJSON(data []byte) error
- func (b *Bool) UnmarshalText(data []byte) error
- type Float32
- func (f *Float32) CAS(old, newz float32) bool
- func (f *Float32) GobDecode(data []byte) error
- func (f *Float32) GobEncode() ([]byte, error)
- func (f *Float32) Load() float32
- func (f *Float32) MarshalBinary() ([]byte, error)
- func (f *Float32) MarshalJSON() ([]byte, error)
- func (f *Float32) MarshalText() ([]byte, error)
- func (f *Float32) Store(s float32)
- func (f *Float32) UnmarshalBinary(data []byte) error
- func (f *Float32) UnmarshalJSON(data []byte) error
- func (f *Float32) UnmarshalText(data []byte) error
- type Float64
- func (f *Float64) CAS(old, newz float64) bool
- func (f *Float64) GobDecode(data []byte) error
- func (f *Float64) GobEncode() ([]byte, error)
- func (f *Float64) Load() float64
- func (f *Float64) MarshalBinary() ([]byte, error)
- func (f *Float64) MarshalJSON() ([]byte, error)
- func (f *Float64) MarshalText() ([]byte, error)
- func (f *Float64) Store(s float64)
- func (f *Float64) UnmarshalBinary(data []byte) error
- func (f *Float64) UnmarshalJSON(data []byte) error
- func (f *Float64) UnmarshalText(data []byte) error
- type Int32
- func (i *Int32) Add(n int32) int32
- func (i *Int32) CAS(old, newz int32) bool
- func (i *Int32) Dec() int32
- func (i *Int32) GobDecode(data []byte) error
- func (i *Int32) GobEncode() ([]byte, error)
- func (i *Int32) Inc() int32
- func (i *Int32) Load() int32
- func (i *Int32) MarshalBinary() ([]byte, error)
- func (i *Int32) MarshalJSON() ([]byte, error)
- func (i *Int32) MarshalText() ([]byte, error)
- func (i *Int32) Store(n int32)
- func (i *Int32) Sub(n int32) int32
- func (i *Int32) Swap(n int32) int32
- func (i *Int32) UnmarshalBinary(data []byte) error
- func (i *Int32) UnmarshalJSON(data []byte) error
- func (i *Int32) UnmarshalText(data []byte) error
- type Int64
- func (i *Int64) Add(n int64) int64
- func (i *Int64) CAS(old, newz int64) bool
- func (i *Int64) Dec() int64
- func (i *Int64) GobDecode(data []byte) error
- func (i *Int64) GobEncode() ([]byte, error)
- func (i *Int64) Inc() int64
- func (i *Int64) Load() int64
- func (i *Int64) MarshalBinary() ([]byte, error)
- func (i *Int64) MarshalJSON() ([]byte, error)
- func (i *Int64) MarshalText() ([]byte, error)
- func (i *Int64) Store(n int64)
- func (i *Int64) Sub(n int64) int64
- func (i *Int64) Swap(n int64) int64
- func (i *Int64) UnmarshalBinary(data []byte) error
- func (i *Int64) UnmarshalJSON(data []byte) error
- func (i *Int64) UnmarshalText(data []byte) error
- type String
- func (s *String) GobDecode(data []byte) error
- func (s *String) GobEncode() ([]byte, error)
- func (s *String) Load() string
- func (s *String) MarshalBinary() ([]byte, error)
- func (s *String) MarshalJSON() ([]byte, error)
- func (s *String) MarshalText() ([]byte, error)
- func (s *String) Store(str string)
- func (s *String) UnmarshalBinary(data []byte) error
- func (s *String) UnmarshalJSON(data []byte) error
- func (s *String) UnmarshalText(data []byte) error
- type Uint32
- func (i *Uint32) Add(n uint32) uint32
- func (i *Uint32) CAS(old, newz uint32) bool
- func (i *Uint32) Dec() uint32
- func (i *Uint32) GobDecode(data []byte) error
- func (i *Uint32) GobEncode() ([]byte, error)
- func (i *Uint32) Inc() uint32
- func (i *Uint32) Load() uint32
- func (i *Uint32) MarshalBinary() ([]byte, error)
- func (i *Uint32) MarshalJSON() ([]byte, error)
- func (i *Uint32) MarshalText() ([]byte, error)
- func (i *Uint32) Store(n uint32)
- func (i *Uint32) Sub(n uint32) uint32
- func (i *Uint32) Swap(n uint32) uint32
- func (i *Uint32) UnmarshalBinary(data []byte) error
- func (i *Uint32) UnmarshalJSON(data []byte) error
- func (i *Uint32) UnmarshalText(data []byte) error
- type Uint64
- func (i *Uint64) Add(n uint64) uint64
- func (i *Uint64) CAS(old, newz uint64) bool
- func (i *Uint64) Dec() uint64
- func (i *Uint64) GobDecode(data []byte) error
- func (i *Uint64) GobEncode() ([]byte, error)
- func (i *Uint64) Inc() uint64
- func (i *Uint64) Load() uint64
- func (i *Uint64) MarshalBinary() ([]byte, error)
- func (i *Uint64) MarshalJSON() ([]byte, error)
- func (i *Uint64) MarshalText() ([]byte, error)
- func (i *Uint64) Store(n uint64)
- func (i *Uint64) Sub(n uint64) uint64
- func (i *Uint64) Swap(n uint64) uint64
- func (i *Uint64) UnmarshalBinary(data []byte) error
- func (i *Uint64) UnmarshalJSON(data []byte) error
- func (i *Uint64) UnmarshalText(data []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultEndian = binary.BigEndian
默认字节序 大端法
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is an atomic Boolean.
func (*Bool) MarshalBinary ¶
func (*Bool) MarshalJSON ¶
func (*Bool) MarshalText ¶
func (*Bool) UnmarshalBinary ¶
func (*Bool) UnmarshalJSON ¶
func (*Bool) UnmarshalText ¶
type Float32 ¶
type Float32 struct {
// contains filtered or unexported fields
}
Float32 is an atomic wrapper around float32.
func (*Float32) MarshalBinary ¶
func (*Float32) MarshalJSON ¶
func (*Float32) MarshalText ¶
func (*Float32) UnmarshalBinary ¶
func (*Float32) UnmarshalJSON ¶
func (*Float32) UnmarshalText ¶
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 is an atomic wrapper around float64.
func (*Float64) MarshalBinary ¶
func (*Float64) MarshalJSON ¶
func (*Float64) MarshalText ¶
func (*Float64) UnmarshalBinary ¶
func (*Float64) UnmarshalJSON ¶
func (*Float64) UnmarshalText ¶
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 is an atomic wrapper around an int32.
func (*Int32) MarshalBinary ¶
func (*Int32) MarshalJSON ¶
func (*Int32) MarshalText ¶
func (*Int32) UnmarshalBinary ¶
func (*Int32) UnmarshalJSON ¶
func (*Int32) UnmarshalText ¶
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 is an atomic wrapper around an int64.
func (*Int64) MarshalBinary ¶
func (*Int64) MarshalJSON ¶
func (*Int64) MarshalText ¶
func (*Int64) UnmarshalBinary ¶
func (*Int64) UnmarshalJSON ¶
func (*Int64) UnmarshalText ¶
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an atomic type-safe wrapper around atomic.Value for strings.
func (*String) MarshalBinary ¶
func (*String) MarshalJSON ¶
func (*String) MarshalText ¶
func (*String) Store ¶
Store atomically stores the passed string. Note: Converting the string to an interface{} to store in the atomic.Value requires an allocation.
func (*String) UnmarshalBinary ¶
func (*String) UnmarshalJSON ¶
func (*String) UnmarshalText ¶
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an atomic wrapper around an uint32.
func (*Uint32) MarshalBinary ¶
func (*Uint32) MarshalJSON ¶
func (*Uint32) MarshalText ¶
func (*Uint32) UnmarshalBinary ¶
func (*Uint32) UnmarshalJSON ¶
func (*Uint32) UnmarshalText ¶
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 is an atomic wrapper around a uint64.
func (*Uint64) MarshalBinary ¶
func (*Uint64) MarshalJSON ¶
func (*Uint64) MarshalText ¶
func (*Uint64) UnmarshalBinary ¶
func (*Uint64) UnmarshalJSON ¶
func (*Uint64) UnmarshalText ¶
Click to show internal directories.
Click to hide internal directories.