28 lines
400 B
Go
28 lines
400 B
Go
|
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)
|
||
|
}
|
||
|
}
|