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

32 lines
506 B
Go

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