Documentation
¶
Index ¶
- type Bool
- func (x *Bool) CompareAndSwap(old, new bool) (swapped bool)
- func (x *Bool) Load() bool
- func (x *Bool) MarshalJSON() ([]byte, error)
- func (x *Bool) Store(val bool)
- func (b *Bool) String() string
- func (x *Bool) Swap(val bool) (old bool)
- func (b *Bool) Toggle() (old bool)
- func (x *Bool) UnmarshalJSON(b []byte) error
- type IntNumber
- func (that *IntNumber[T]) Add(delta T) T
- func (that *IntNumber[T]) CAS(old, new T) (swapped bool)
- func (that *IntNumber[T]) CompareAndSwap(old, new T) bool
- func (that *IntNumber[T]) Dec() T
- func (that *IntNumber[T]) Inc() T
- func (that *IntNumber[T]) Load() T
- func (that *IntNumber[T]) MarshalJSON() ([]byte, error)
- func (that *IntNumber[T]) Store(val T)
- func (that *IntNumber[T]) String() string
- func (that *IntNumber[T]) Sub(delta T) T
- func (that *IntNumber[T]) Swap(val T) (old T)
- func (that *IntNumber[T]) UnmarshalJSON(b []byte) error
- type NumberConstraints
- type Uint32
- func (i *Uint32) Add(delta uint32) uint32
- func (i *Uint32) CAS(old, new uint32) (swapped bool)deprecated
- func (i *Uint32) CompareAndSwap(old, new uint32) (swapped 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(val uint32)
- func (i *Uint32) String() string
- func (i *Uint32) Sub(delta uint32) uint32
- func (i *Uint32) Swap(val uint32) (old uint32)
- func (i *Uint32) UnmarshalJSON(b []byte) error
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) CompareAndSwap ¶
CompareAndSwap is an atomic compare-and-swap for bool values.
func (*Bool) MarshalJSON ¶
MarshalJSON encodes the wrapped bool into JSON.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON decodes a bool from JSON.
type IntNumber ¶
type IntNumber[T NumberConstraints] struct { // contains filtered or unexported fields }
func NewStatus ¶
func NewStatus[T NumberConstraints](val T) *IntNumber[T]
NewStatus 创建一个新的 Status 实例,并设置其值为 val
func (*IntNumber[T]) Add ¶
func (that *IntNumber[T]) Add(delta T) T
向 Status 结构体的值添加指定的增量,并返回新的值。
参数: @param delta 是要添加的增量,类型为泛型 T。 返回值: @return 是添加增量后的新值,类型为泛型 T。
func (*IntNumber[T]) CAS ¶
CAS 函数尝试以原子方式将 IntNumber 的值从旧值更新为新值。 如果当前值等于旧值,则将其设置为新值,并返回 true,表示成功交换。 如果当前值不等于旧值,则不进行修改,并返回 false,表示未进行交换。
参数: @param old:期望的旧值 @param new:要设置的新值 返回值: @return 如果成功交换了值,则返回 true;否则返回 false。
func (*IntNumber[T]) CompareAndSwap ¶
CompareAndSwap 方法尝试将 IntNumber 的值从 old 更新为 new。 如果当前值为 old,则更新为 new 并返回 true;否则,不执行更新并返回 false。
参数: @param old:期望的旧值 @param new:要设置的新值 返回值: @return 如果成功交换了值,则返回 true;否则返回 false。
func (*IntNumber[T]) Dec ¶
func (that *IntNumber[T]) Dec() T
Dec 方法用于对 Status 类型的值进行递减操作
参数: that: *Status[T] 类型的指针,表示要进行递减操作的状态对象 返回值: T: 递减后的值
func (*IntNumber[T]) Inc ¶
func (that *IntNumber[T]) Inc() T
Inc 方法对 Status 结构体中的值进行自增操作
参数: that: *Status[T] 类型的指针,表示要进行递增操作的状态对象 返回值: T: 递增后的值
func (*IntNumber[T]) Load ¶
func (that *IntNumber[T]) Load() T
加载 Status 实例中存储的值。
返回值: @return 返回一个类型为 T 的值。如果 T 是 int8, int16, int32, int64, uint8, uint16, uint32 或 uint64 之一,它将使用 atomic 包中的 Load 函数来安全地加载值。如果 T 不是这些类型之一,则会导致 panic。
func (*IntNumber[T]) MarshalJSON ¶
func (*IntNumber[T]) Store ¶
func (that *IntNumber[T]) Store(val T)
Store 将给定的值存储到 IntNumber 实例中。
参数: @param val: 要存储的值。 说明: 该方法使用 atomic 包提供的原子操作来保证对 IntNumber 实例中值的修改是线程安全的。 它首先使用 type switch 判断 that.v 的具体类型,然后根据不同的类型使用相应的 atomic.Store 函数进行存储。 如果 that.v 的类型不是 int8, int16, int32, int64, uint8, uint16, uint32, uint64 之一, 则会引发 panic,并抛出 "unsupported type" 错误信息。
func (*IntNumber[T]) Sub ¶
func (that *IntNumber[T]) Sub(delta T) T
Sub 从当前状态值中减去 delta 并返回新的状态值。
参数: @param delta: 要减去的值。 返回值: @return 返回减去 delta 后的新状态值。
func (*IntNumber[T]) Swap ¶
func (that *IntNumber[T]) Swap(val T) (old T)
Swap 方法用于原子性地交换 IntNumber 实例中的值。
参数: @param val 是要交换进去的新值。 返回值: @retuan 返回原来的值 old。如果 IntNumber 实例中存储的值类型不支持原子操作,则触发 panic。
func (*IntNumber[T]) UnmarshalJSON ¶
type NumberConstraints ¶
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an atomic wrapper around uint32.
func (*Uint32) CompareAndSwap ¶
CompareAndSwap is an atomic compare-and-swap.
func (*Uint32) MarshalJSON ¶
MarshalJSON encodes the wrapped uint32 into JSON.
func (*Uint32) UnmarshalJSON ¶
UnmarshalJSON decodes JSON into the wrapped uint32.