diff options
| author | ruki <[email protected]> | 2021-07-09 22:52:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-07-09 11:23:39 +0800 |
| commit | f1220d5f22e936744129d07cb06ccc0f5127d5d6 (patch) | |
| tree | ebb485a4666c06a82c2747946f90b8cbe5a2e451 | |
| parent | 0b09f8fe41184b539e1bbf3aa0086794a77708a0 (diff) | |
fix timer jobs and envs bug
| -rw-r--r-- | xmake/core/base/scheduler.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/async/runjobs.lua | 98 |
2 files changed, 55 insertions, 45 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 1165538d7..70ba07414 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -551,7 +551,7 @@ end -- get waiting objects for the given group name function scheduler:co_group_waitobjs(name) local objs = hashset.new() - for _, co in ipairs(self:co_group(name)) do + for _, co in ipairs(table.wrap(self:co_group(name))) do if not co:is_dead() then local obj = co:waitobj() if obj then diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua index ed007291c..0361399dc 100644 --- a/xmake/modules/private/async/runjobs.lua +++ b/xmake/modules/private/async/runjobs.lua @@ -84,60 +84,67 @@ function main(name, jobs, opt) -- run timer local stop = false local running_jobs_indices = {} + local group_timer if opt.on_timer then - scheduler.co_start_withopt({name = name .. "/timer", isolate = opt.isolate}, function () - while not stop do - os.sleep(timeout) - if not stop then - local indices - if running_jobs_indices then - indices = table.keys(running_jobs_indices) + group_timer = group_name .. "/timer" + scheduler.co_group_begin(group_timer, function (co_group) + scheduler.co_start_withopt({name = name .. "/timer", isolate = opt.isolate}, function () + while not stop do + os.sleep(timeout) + if not stop then + local indices + if running_jobs_indices then + indices = table.keys(running_jobs_indices) + end + opt.on_timer(indices) end - opt.on_timer(indices) end - end + end) end) elseif showprogress then - scheduler.co_start_withopt({name = name .. "/tips", isolate = opt.isolate}, function () - while not stop do - os.sleep(timeout) - if not stop then + group_timer = group_name .. "/timer" + scheduler.co_group_begin(group_timer, function (co_group) + scheduler.co_start_withopt({name = name .. "/tips", isolate = opt.isolate}, function () + while not stop do + os.sleep(timeout) + if not stop then - -- show waitchars - local tips = nil - local waitobjs = scheduler.co_group_waitobjs(group_name) - if waitobjs:size() > 0 then - local names = {} - for _, obj in waitobjs:keys() do - if obj:otype() == scheduler.OT_PROC then - table.insert(names, obj:name()) - elseif obj:otype() == scheduler.OT_SOCK then - table.insert(names, "sock") - elseif obj:otype() == scheduler.OT_PIPE then - table.insert(names, "pipe") + -- show waitchars + local tips = nil + local waitobjs = scheduler.co_group_waitobjs(group_name) + if waitobjs:size() > 0 then + local names = {} + for _, obj in waitobjs:keys() do + if obj:otype() == scheduler.OT_PROC then + table.insert(names, obj:name()) + elseif obj:otype() == scheduler.OT_SOCK then + table.insert(names, "sock") + elseif obj:otype() == scheduler.OT_PIPE then + table.insert(names, "pipe") + end end - end - names = table.unique(names) - if #names > 0 then - names = table.concat(names, ",") - if #names > 16 then - names = names:sub(1, 16) .. ".." + names = table.unique(names) + if #names > 0 then + names = table.concat(names, ",") + if #names > 16 then + names = names:sub(1, 16) .. ".." + end + tips = string.format("(%d/%s)", waitobjs:size(), names) end - tips = string.format("(%d/%s)", waitobjs:size(), names) end - end - -- print back characters - progress_helper:clear() - _print_backchars(backnum) + -- print back characters + progress_helper:clear() + _print_backchars(backnum) - if tips then - cprintf("${dim}%s${clear} ", tips) - backnum = #tips + 1 + if tips then + cprintf("${dim}%s${clear} ", tips) + backnum = #tips + 1 + end + progress_helper:write() end - progress_helper:write() end - end + end) end) end @@ -243,14 +250,17 @@ function main(name, jobs, opt) -- wait all jobs exited scheduler.co_group_wait(group_name) + -- wait timer job exited + if group_timer then + stop = true + scheduler.co_group_wait(group_timer) + end + -- restore isolated environments if co_running and opt.isolate then co_running:isolate(is_isolated) end - -- stop timer - stop = true - -- remove wait charactor if showprogress then _print_backchars(backnum) |
