kde-lockscreen-suspend-display/atomicflag/atomicflag.go

28 lines
366 B
Go
Raw Normal View History

package atomicflag
import (
"sync"
)
2020-08-18 10:30:39 +00:00
type AtomicFlag struct {
value bool
mutex sync.RWMutex
}
2020-08-18 10:30:39 +00:00
func New(value bool) *AtomicFlag {
return &AtomicFlag{value: value}
}
2020-08-18 10:30:39 +00:00
func (f *AtomicFlag) Get() bool {
f.mutex.RLock()
defer f.mutex.RUnlock()
return f.value
}
2020-08-18 10:30:39 +00:00
func (f *AtomicFlag) Set(value bool) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.value = value
}