diff options
| author | ruki <[email protected]> | 2020-02-05 23:09:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-07 22:45:56 +0800 |
| commit | a1e36f03bcae56c52c36ca1692725330cd173043 (patch) | |
| tree | bf1085d08ff5fe430f41c41d7f26502d1a6ec448 | |
| parent | 97d20dc309b8064ab7bafc69a6784caa4df9b107 (diff) | |
add scheduler:co_group_waitobjs
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 29 | ||||
| -rw-r--r-- | xmake/core/base/scheduler.lua | 14 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/scheduler.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/private/async/runjobs.lua | 16 |
4 files changed, 47 insertions, 17 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index 8da0e94df..0f34a8839 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -22,6 +22,7 @@ import("core.base.semver") import("core.base.option") import("core.base.global") +import("core.base.hashset") import("core.base.scheduler") import("private.async.runjobs") import("lib.detect.cache", {alias = "detectcache"}) @@ -656,7 +657,31 @@ function _install_packages(packages_install, packages_download) table.insert(downloading, package:name()) end end - + + -- get waitobjs tips + local tips = nil + local waitobjs = scheduler.co_group_waitobjs("install_packages") + 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 + 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 + end + -- trace utils.clearline() cprintf("${yellow} => ${clear}") @@ -666,7 +691,7 @@ function _install_packages(packages_install, packages_download) if #installing > 0 then cprintf("%sinstalling ${magenta}%s${clear}", #downloading > 0 and ", " or "", table.concat(installing, ", ")) end - cprintf(" .. %s", waitchars[waitindex + 1]) + cprintf(" .. %s%s", tips and ("${dim}" .. tips .. "${clear} ") or "", waitchars[waitindex + 1]) io.flush() end}) end diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 5e68be8c2..63829a913 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -453,6 +453,20 @@ function scheduler:co_group_wait(name) return true 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 + if not co:is_dead() then + local obj = co:waitobj() + if obj then + objs:insert(obj) + end + end + end + return objs +end + -- get the current running coroutine function scheduler:co_running() local running = coroutine.running() diff --git a/xmake/core/sandbox/modules/import/core/base/scheduler.lua b/xmake/core/sandbox/modules/import/core/base/scheduler.lua index 254f78591..346255ffb 100644 --- a/xmake/core/sandbox/modules/import/core/base/scheduler.lua +++ b/xmake/core/sandbox/modules/import/core/base/scheduler.lua @@ -96,6 +96,11 @@ function sandbox_core_base_scheduler.co_group_wait(name) end end +-- get the waiting poller objects of the given coroutine group +function sandbox_core_base_scheduler.co_group_waitobjs(name) + return scheduler:co_group_waitobjs(name) +end + -- get the current running coroutine function sandbox_core_base_scheduler.co_running() return scheduler:co_running() diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua index fcca3e65d..0e56963b3 100644 --- a/xmake/modules/private/async/runjobs.lua +++ b/xmake/modules/private/async/runjobs.lua @@ -22,20 +22,6 @@ import("core.base.scheduler") import("core.base.hashset") --- get waiting objects -function _get_waiting_objects(group_name) - local objs = hashset.new() - for _, co in ipairs(scheduler.co_group(group_name)) do - if not co:is_dead() then - local obj = co:waitobj() - if obj then - objs:insert(obj) - end - end - end - return objs -end - -- print back characters function _print_backchars(backnum) if backnum > 0 then @@ -96,7 +82,7 @@ function main(name, jobfunc, opt) -- show waitchars waitindex = ((waitindex + 1) % #waitchars) local tips = nil - local waitobjs = _get_waiting_objects(group_name) + local waitobjs = scheduler.co_group_waitobjs(group_name) if waitobjs:size() > 0 then local names = {} for _, obj in waitobjs:keys() do |
