Compare commits

...

1 Commits

Author SHA1 Message Date
496c4e4f59 v0.0.23 2022-11-30 23:08:50 +01:00

27
syncext/atomic.go Normal file
View 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)
}
}