Fetch the repository succeeded.
package cast
import (
"fmt"
"sync"
"sync/atomic"
)
var atomMutex sync.Mutex
func LockAtom() {
atomMutex.Lock()
}
func UnlockAtom() {
atomMutex.Unlock()
}
// ////////////////////////////int32////////////////////////////
type Int struct {
atomic.Int32
}
func (me *Int) Set(v int32) int32 {
return me.Swap(v)
}
func (me *Int) Inc() int32 {
return me.Add(1)
}
func (me *Int) Dec() int32 {
return me.Add(-1)
}
func (me *Int) Get() int32 {
return me.Load()
}
func (me *Int) ToString() string {
return fmt.Sprintf("%d", me.Load())
}
type UInt struct {
atomic.Uint32
}
func (me *UInt) Set(v uint32) uint32 {
return me.Swap(v)
}
func (me *UInt) Inc() uint32 {
return me.Add(1)
}
func (me *UInt) Dec() uint32 {
return 0
}
func (me *UInt) Get() uint32 {
return me.Load()
}
func (me *UInt) ToString() string {
return fmt.Sprintf("%d", me.Load())
}
type UInt16 struct {
atomic.Uint32
}
func (me *UInt16) Add(v uint16) uint16 {
value := me.Uint32.Add(uint32(v))
return uint16(value)
}
func (me *UInt16) Set(v uint16) uint16 {
return uint16(me.Swap(uint32(v)))
}
func (me *UInt16) Inc() uint16 {
return me.Add(1)
}
func (me *UInt16) Dec() uint16 {
return 0
}
func (me *UInt16) Get() uint16 {
return uint16(me.Load())
}
func (me *UInt16) ToString() string {
return fmt.Sprintf("%d", me.Get())
}
// ////////////////////////////int64////////////////////////////
type Int64 struct {
atomic.Int64
}
func (me *Int64) Set(v int64) int64 {
return me.Swap(v)
}
func (me *Int64) Inc() int64 {
return me.Add(1)
}
func (me *Int64) Dec() int64 {
return me.Add(-1)
}
func (me *Int64) Get() int64 {
return me.Load()
}
func (me *Int64) ToString() string {
return fmt.Sprintf("%d", me.Load())
}
type UInt64 struct {
atomic.Uint64
}
func (me *UInt64) Set(v uint64) uint64 {
return me.Swap(v)
}
func (me *UInt64) Inc() uint64 {
return me.Add(1)
}
func (me *UInt64) Dec() uint64 {
return 0
}
func (me *UInt64) Get() uint64 {
return me.Load()
}
func (me *UInt64) ToString() string {
return fmt.Sprintf("%d", me.Load())
}
// ////////////////////////////Bool////////////////////////////
type Bool struct {
atomic.Bool
}
func (me *Bool) Set(v bool) bool {
return me.Swap(v)
}
func (me *Bool) Get() bool {
return me.Load()
}
////////////////////////////string////////////////////////////////
type String struct {
atomic.Pointer[string]
}
func (me *String) Set(v string) string {
ptr := me.Swap(&v)
if ptr != nil {
return *ptr
}
return ""
}
func (me *String) Get() string {
return *me.Load()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。