Simplify stop logic (closing a RO fd is not worth the added complexity)

This commit is contained in:
Kristóf Tóth 2020-09-08 15:41:31 +02:00
parent 93da02bf90
commit b652c48bd4

View File

@ -2,7 +2,6 @@ package afterlock
import( import(
"time" "time"
"sync"
"errors" "errors"
) )
@ -28,8 +27,6 @@ type AfterLock struct {
InitialDelay uint InitialDelay uint
LoopDelay uint LoopDelay uint
keyboardDeviceNode string keyboardDeviceNode string
wg sync.WaitGroup
stopFlag *AtomicFlag
keypressFlag *AtomicFlag keypressFlag *AtomicFlag
Display Display Display Display
LockScreen Lockscreen LockScreen Lockscreen
@ -40,7 +37,6 @@ type AfterLock struct {
func New(keyboardDeviceNode string) *AfterLock { func New(keyboardDeviceNode string) *AfterLock {
return &AfterLock{ return &AfterLock{
keyboardDeviceNode: keyboardDeviceNode, keyboardDeviceNode: keyboardDeviceNode,
stopFlag: NewAtomicFlag(false),
keypressFlag: NewAtomicFlag(false), keypressFlag: NewAtomicFlag(false),
} }
} }
@ -52,7 +48,6 @@ func New(keyboardDeviceNode string) *AfterLock {
func (af *AfterLock) Start() { func (af *AfterLock) Start() {
af.checkStructConfigured() af.checkStructConfigured()
af.wg.Add(1)
go af.detectKeypresses() go af.detectKeypresses()
time.Sleep(time.Duration(af.InitialDelay) * time.Second) time.Sleep(time.Duration(af.InitialDelay) * time.Second)
@ -83,10 +78,6 @@ func (af *AfterLock) detectKeypresses() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if af.stopFlag.Get() {
af.wg.Done()
return
}
af.keypressFlag.Set(true) af.keypressFlag.Set(true)
} }
} }
@ -98,8 +89,6 @@ func (af *AfterLock) hybernateDisplayLoop() {
panic(err) panic(err)
} }
if !screenLocked { if !screenLocked {
af.stopFlag.Set(true)
af.wg.Wait()
return return
} }