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

32 lines
506 B
Go
Raw Normal View History

package afterlock
import (
"sync"
)
// AtomicFlag implements a simple, thread-safe boolean flag
2020-08-18 10:30:39 +00:00
type AtomicFlag struct {
value bool
mutex sync.RWMutex
}
// NewAtomicFlag builds a new instance
func NewAtomicFlag(value bool) *AtomicFlag {
2020-08-18 10:30:39 +00:00
return &AtomicFlag{value: value}
}
// Get the flag
2020-08-18 10:30:39 +00:00
func (f *AtomicFlag) Get() bool {
f.mutex.RLock()
defer f.mutex.RUnlock()
return f.value
}
// Set the flag
2020-08-18 10:30:39 +00:00
func (f *AtomicFlag) Set(value bool) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.value = value
}