Fix duplicate suspend scheduling in Device:onPowerEvent

We should always unschedule suspend before scheduling it again (i.e.,
use rescheduleSuspend ;)).

Fix #8097 (many thanks to @Mel-kior for the detailed repro!)
reviewable/pr8109/r1
NiLuJe 3 years ago
parent c044480658
commit edfb29b406

@ -341,7 +341,7 @@ function Device:onPowerEvent(ev)
-- Only actually schedule suspension if we're still supposed to go to sleep, -- Only actually schedule suspension if we're still supposed to go to sleep,
-- because the Wi-Fi stuff above may have blocked for a significant amount of time... -- because the Wi-Fi stuff above may have blocked for a significant amount of time...
if self.screen_saver_mode then if self.screen_saver_mode then
UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend) self:rescheduleSuspend()
end end
end) end)
end end

@ -1178,16 +1178,15 @@ function UIManager:_checkTasks()
-- task.action may schedule other events -- task.action may schedule other events
self._task_queue_dirty = false self._task_queue_dirty = false
while true do while true do
local nu_task = #self._task_queue if #self._task_queue == 0 then
if nu_task == 0 then -- Nothing to do!
-- all tasks checked
break break
end end
local task = self._task_queue[1] local next_task = self._task_queue[1]
local task_tv = task.time or TimeVal.zero local task_tv = next_task.time or TimeVal.zero
if task_tv <= self._now then if task_tv <= self._now then
-- remove from table -- remove from table
table.remove(self._task_queue, 1) local task = table.remove(self._task_queue, 1)
-- task is pending to be executed right now. do it. -- task is pending to be executed right now. do it.
-- NOTE: be careful that task.action() might modify -- NOTE: be careful that task.action() might modify
-- _task_queue here. So need to avoid race condition -- _task_queue here. So need to avoid race condition
@ -1195,7 +1194,7 @@ function UIManager:_checkTasks()
else else
-- queue is sorted in ascendant order, safe to assume all items -- queue is sorted in ascendant order, safe to assume all items
-- are future tasks for now -- are future tasks for now
wait_until = task.time wait_until = next_task.time
break break
end end
end end

Loading…
Cancel
Save