summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-04 00:55:54 +0800
committerruki <[email protected]>2020-03-03 23:35:28 +0800
commita9b635bcfc79a46e307a3b8ba7dee3477191257f (patch)
tree8c6371d9ae8b219e742193de1cd2c2c69a14b526
parentc414be7d555e3b0c9eb3626c773f602cb2635365 (diff)
improve scheduler again
-rw-r--r--xmake/core/base/scheduler.lua44
1 files changed, 26 insertions, 18 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index b71d8ff83..615377a86 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -260,27 +260,31 @@ function scheduler:_co_groups_resume()
local co_groups = self._CO_GROUPS
if co_groups then
for name, co_group in pairs(co_groups) do
+
+ -- get coroutine and limit in waiting group
+ local co_group_waiting = self._CO_GROUPS_WAITING[name]
+ local co_waiting = co_group_waiting[1]
+ local limit = co_group_waiting[2]
+
+ -- get dead coroutines count in this group
local count = 0
for _, co in ipairs(co_group) do
- if co:is_dead() then
- count = count + 1
+ if count < limit then
+ if co:is_dead() then
+ count = count + 1
+ end
+ else
+ break
end
end
- -- some coroutines are dead in this group?
- if count > 0 then
-
- -- resume the waiting coroutine of this group
- local co_group_waiting = self._CO_GROUPS_WAITING[name]
- local co_waiting = co_group_waiting[1]
- local limit = co_group_waiting[2]
- if count >= limit and co_waiting and co_waiting:is_suspended() then
- resumed_count = resumed_count + 1
- self._CO_GROUPS_WAITING[name] = nil
- local ok, errors = self:co_resume(co_waiting)
- if not ok then
- return -1, errors
- end
+ -- resume the waiting coroutine of this group if some coroutines are dead in this group
+ if count >= limit and co_waiting and co_waiting:is_suspended() then
+ resumed_count = resumed_count + 1
+ self._CO_GROUPS_WAITING[name] = nil
+ local ok, errors = self:co_resume(co_waiting)
+ if not ok then
+ return -1, errors
end
end
end
@@ -451,8 +455,12 @@ function scheduler:co_group_wait(name, opt)
repeat
count = 0
for _, co in ipairs(co_group) do
- if co:is_dead() then
- count = count + 1
+ if count < limit then
+ if co:is_dead() then
+ count = count + 1
+ end
+ else
+ break
end
end
if count < limit then