Files
mostlymatter/vendor/github.com/splitio/go-toolkit/v4/sync/atomicbool.go
Joram Wilander aba00a3cfd Update split SDK to 6.0.2 to fix sync bug (#17060)
* Update split SDK to 6.0.2 to fix sync bug

* Vendor and tidy
2021-03-04 11:16:08 -05:00

42 строки
728 B
Go

package sync
import (
"sync/atomic"
)
const (
falseValue = 0
trueValue = 1
)
type AtomicBool struct {
value uint32
}
func (b *AtomicBool) Set() {
atomic.StoreUint32(&b.value, trueValue)
}
func (b *AtomicBool) Unset() {
atomic.StoreUint32(&b.value, falseValue)
}
func (b *AtomicBool) IsSet() bool {
return atomic.LoadUint32(&b.value) == trueValue
}
func (b *AtomicBool) TestAndSet() bool {
return atomic.CompareAndSwapUint32(&b.value, falseValue, trueValue)
}
func (b *AtomicBool) TestAndClear() bool {
return atomic.CompareAndSwapUint32(&b.value, trueValue, falseValue)
}
func NewAtomicBool(initialValue bool) *AtomicBool {
if initialValue {
return &AtomicBool{value: trueValue}
}
return &AtomicBool{}
}