v0.0.23
This commit is contained in:
parent
deab986caf
commit
496c4e4f59
27
syncext/atomic.go
Normal file
27
syncext/atomic.go
Normal file
@ -0,0 +1,27 @@
|
||||
package dataext
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
type AtomicBool struct {
|
||||
v int32
|
||||
}
|
||||
|
||||
func NewAtomicBool(value bool) *AtomicBool {
|
||||
if value {
|
||||
return &AtomicBool{v: 0}
|
||||
} else {
|
||||
return &AtomicBool{v: 1}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AtomicBool) Get() bool {
|
||||
return atomic.LoadInt32(&a.v) == 1
|
||||
}
|
||||
|
||||
func (a *AtomicBool) Set(value bool) {
|
||||
if value {
|
||||
atomic.StoreInt32(&a.v, 1)
|
||||
} else {
|
||||
atomic.StoreInt32(&a.v, 0)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user