initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

38
core/syncx/atomicbool.go Normal file
View File

@@ -0,0 +1,38 @@
package syncx
import "sync/atomic"
type AtomicBool uint32
func NewAtomicBool() *AtomicBool {
return new(AtomicBool)
}
func ForAtomicBool(val bool) *AtomicBool {
b := NewAtomicBool()
b.Set(val)
return b
}
func (b *AtomicBool) CompareAndSwap(old, val bool) bool {
var ov, nv uint32
if old {
ov = 1
}
if val {
nv = 1
}
return atomic.CompareAndSwapUint32((*uint32)(b), ov, nv)
}
func (b *AtomicBool) Set(v bool) {
if v {
atomic.StoreUint32((*uint32)(b), 1)
} else {
atomic.StoreUint32((*uint32)(b), 0)
}
}
func (b *AtomicBool) True() bool {
return atomic.LoadUint32((*uint32)(b)) == 1
}