perf: automatically suspend the scheduler when all threads are waiting (#1591)

* perf: automatically suspend the scheduler when all threads are waiting

* ci: fix ci

* test: cleanup
This commit is contained in:
Folke Lemaitre 2024-06-30 08:48:03 +02:00 committed by GitHub
parent 0507e19289
commit c7ed87f9ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 81 additions and 54 deletions

View file

@ -78,6 +78,7 @@ function Runner:_start()
---@type number?
local wait_step = nil
---@async
---@param resume? boolean
local function continue(resume)
active = 0
@ -114,22 +115,30 @@ function Runner:_start()
end
local s = state[name]
local plugin = self:plugin(name)
if s.step == #self._pipeline then
-- done
s.task = nil
plugin._.working = false
elseif s.step < #self._pipeline then
-- next
s.step = s.step + 1
local step = self._pipeline[s.step]
if step.task == "wait" then
while s.step <= #self._pipeline do
if s.step == #self._pipeline then
-- done
s.task = nil
plugin._.working = false
waiting = waiting + 1
wait_step = s.step
else
s.task = self:queue(plugin, step)
plugin._.working = true
active = active + 1
break
elseif s.step < #self._pipeline then
-- next
s.step = s.step + 1
local step = self._pipeline[s.step]
if step.task == "wait" then
plugin._.working = false
waiting = waiting + 1
wait_step = s.step
break
else
s.task = self:queue(plugin, step)
plugin._.working = true
if s.task then
active = active + 1
s.task:wake(false)
break
end
end
end
end
end