This commit is contained in:
Mike Schwörer 2022-11-30 23:08:50 +01:00
parent deab986caf
commit 496c4e4f59
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

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)
}
}