2020-07-24 16:12:16 +00:00
|
|
|
package atomicboolean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AtomBool struct {
|
|
|
|
sync.RWMutex
|
|
|
|
flag bool
|
|
|
|
}
|
|
|
|
|
2020-10-17 00:10:47 +00:00
|
|
|
func New() *AtomBool {
|
|
|
|
return &AtomBool{}
|
|
|
|
}
|
|
|
|
|
2020-07-24 16:12:16 +00:00
|
|
|
func (b *AtomBool) Or(value bool) {
|
|
|
|
b.Lock()
|
|
|
|
defer b.Unlock()
|
|
|
|
|
|
|
|
b.flag = b.flag || value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *AtomBool) And(value bool) {
|
|
|
|
b.Lock()
|
|
|
|
defer b.Unlock()
|
|
|
|
|
|
|
|
b.flag = b.flag && value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *AtomBool) Set(value bool) {
|
|
|
|
b.Lock()
|
|
|
|
defer b.Unlock()
|
|
|
|
|
|
|
|
b.flag = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *AtomBool) Get() bool {
|
|
|
|
b.RLock()
|
2020-08-25 21:24:31 +00:00
|
|
|
defer b.RUnlock() //nolint
|
2020-07-24 16:12:16 +00:00
|
|
|
|
|
|
|
return b.flag
|
|
|
|
}
|