idler: fix data race for access to idleing and waiting
Protect access to fields idleing and waiting via a mutex. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
9e54c921c8
commit
978768bff6
1 changed files with 15 additions and 3 deletions
|
@ -60,6 +60,18 @@ func (i *idler) isReady() bool {
|
||||||
i.client.State() == imap.SelectedState)
|
i.client.State() == imap.SelectedState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *idler) setIdleing(v bool) {
|
||||||
|
i.Lock()
|
||||||
|
defer i.Unlock()
|
||||||
|
i.idleing = v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *idler) isIdleing() bool {
|
||||||
|
i.Lock()
|
||||||
|
defer i.Unlock()
|
||||||
|
return i.idleing
|
||||||
|
}
|
||||||
|
|
||||||
func (i *idler) Start() {
|
func (i *idler) Start() {
|
||||||
switch {
|
switch {
|
||||||
case i.isReady():
|
case i.isReady():
|
||||||
|
@ -74,7 +86,7 @@ func (i *idler) Start() {
|
||||||
i.done <- nil
|
i.done <- nil
|
||||||
case <-time.After(i.config.idle_debounce):
|
case <-time.After(i.config.idle_debounce):
|
||||||
// enter idle mode
|
// enter idle mode
|
||||||
i.idleing = true
|
i.setIdleing(true)
|
||||||
i.log("=>(idle)")
|
i.log("=>(idle)")
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
err := i.client.Idle(i.stop,
|
err := i.client.Idle(i.stop,
|
||||||
|
@ -82,7 +94,7 @@ func (i *idler) Start() {
|
||||||
LogoutTimeout: 0,
|
LogoutTimeout: 0,
|
||||||
PollInterval: 0,
|
PollInterval: 0,
|
||||||
})
|
})
|
||||||
i.idleing = false
|
i.setIdleing(false)
|
||||||
i.done <- err
|
i.done <- err
|
||||||
i.log("elapsed idle time: %v", time.Since(now))
|
i.log("elapsed idle time: %v", time.Since(now))
|
||||||
}
|
}
|
||||||
|
@ -154,5 +166,5 @@ func (i *idler) waitOnIdle() {
|
||||||
|
|
||||||
func (i *idler) log(format string, v ...interface{}) {
|
func (i *idler) log(format string, v ...interface{}) {
|
||||||
msg := fmt.Sprintf(format, v...)
|
msg := fmt.Sprintf(format, v...)
|
||||||
logging.Debugf("idler (%p) [idle:%t,wait:%t] %s", i, i.idleing, i.waiting, msg)
|
logging.Debugf("idler (%p) [idle:%t,wait:%t] %s", i, i.isIdleing(), i.isWaiting(), msg)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue