diff options
| author | ruki <[email protected]> | 2020-02-05 00:39:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-07 22:45:56 +0800 |
| commit | 35b8b34362abe28a638af8ee02d3babe8e3548e2 (patch) | |
| tree | a47c0a1da53fffd81f0aa7832ceb3646950bd08a | |
| parent | 94d3eb649e489a597a2f5d966d2249a9e64d87e3 (diff) | |
uses new runjobs
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/process.lua | 142 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/process.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/features.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/net/ping.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 3 |
9 files changed, 22 insertions, 165 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index 4640cfaf6..822dd59ed 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -22,6 +22,8 @@ import("core.base.semver") import("core.base.option") import("core.base.global") +import("core.base.scheduler") +import("private.async.runjobs") import("lib.detect.cache", {alias = "detectcache"}) import("core.project.project") import("core.package.package", {alias = "core_package"}) @@ -539,7 +541,7 @@ function _install_packages(packages_install, packages_download) local packages_in_group = {} local installing_count = 0 local parallelize = true - process.runjobs(function (index) + runjobs("install_packages", function (index) -- fetch a new package local package = nil @@ -575,7 +577,7 @@ function _install_packages(packages_install, packages_download) end if package == nil and #packages_pending > 0 then local curdir = os.curdir() - coroutine.yield() + scheduler.co_yield() os.cd(curdir) end end @@ -592,7 +594,7 @@ function _install_packages(packages_install, packages_download) if not parallelize then while installing_count > 0 do local curdir = os.curdir() - coroutine.yield() + scheduler.co_yield() os.cd(curdir) end end @@ -718,7 +720,7 @@ function install_packages(requires, opt) local packages = load_packages(requires, opt) -- fetch packages (with system) from local first - process.runjobs(function (index) + runjobs("fetch_packages", function (index) local package = packages[index] if package and (not option.get("force") or (option.get("shallow") and package:parents())) then package:envs_enter() diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index 6f5696786..05d9046f5 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -326,147 +326,5 @@ function process.asyncrun(task, waitchars) return true end --- run jobs with processes -function process.runjobs(jobfunc, total, comax, timeout, timer) - - -- init max coroutine count - comax = comax or total - - -- init timeout - timeout = timeout or -1 - - -- make objects - local index = 1 - local tasks = {} - local procs = {} - local indices = {} - local time = os.mclock() - repeat - - -- wait processes - local tasks_finished = {} - local procs_count = #procs - local procs_infos = nil - if procs_count > 0 then - local count = -1 - count, procs_infos = process.waitlist(procs, utils.ifelse(#tasks < comax and index <= total, 0, timeout)) - if count < 0 then - return false, string.format("wait processes(%d) failed(%d)", #procs, count) - end - end - - -- timer is triggered? call timer - if timer and os.mclock() - time > timeout then - local tips = nil - if #procs > 0 then - local names = {} - for _, proc in ipairs(procs) do - table.insert(names, proc:name()) - 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)", #procs, names) - end - end - timer(indices, tips) - time = os.mclock() - end - - -- append fake procs_infos for coroutine.yield() - procs_infos = procs_infos or {} - for taskid = #procs + 1, #tasks do - table.insert(procs_infos, {nil, taskid, 0}) - end - - -- wait ok - for _, procinfo in ipairs(procs_infos) do - - -- the process info - local proc = procinfo[1] - local taskid = procinfo[2] - local status = procinfo[3] - - -- check - assert(procs[taskid] == proc) - - -- resume this task - local job_task = tasks[taskid] - local ok, job_proc_or_errors = coroutine.resume(job_task, 1, status) - if not ok then - return false, job_proc_or_errors - end - - -- the other process is pending for this task? - if coroutine.status(job_task) ~= "dead" then - procs[taskid] = job_proc_or_errors - else - -- mark this task as finished? - tasks_finished[taskid] = true - end - end - - -- update the pending tasks and procs - local tasks_pending1 = {} - local procs_pending1 = {} - local indices_pending1 = {} - local tasks_pending2 = {} - local indices_pending2 = {} - for taskid, job_task in ipairs(tasks) do - if not tasks_finished[taskid] and procs[taskid] ~= nil then -- for coroutine.yield(proc) in os.execv - table.insert(tasks_pending1, job_task) - table.insert(procs_pending1, procs[taskid]) - table.insert(indices_pending1, indices[taskid]) - end - end - for taskid, job_task in ipairs(tasks) do - if not tasks_finished[taskid] and procs[taskid] == nil then -- for coroutine.yield() - table.insert(tasks_pending2, job_task) - table.insert(indices_pending2, indices[taskid]) - end - end - - -- produce tasks - while (#tasks_pending1 + #tasks_pending2) < comax and index <= total do - - -- new task - local job_task = coroutine.create(jobfunc) - - -- resume it first - local ok, job_proc_or_errors = coroutine.resume(job_task, index) - if not ok then - return false, job_proc_or_errors - end - - -- add pending tasks - if coroutine.status(job_task) ~= "dead" then - if job_proc_or_errors ~= nil then -- for coroutine.yield(proc) in os.execv - table.insert(tasks_pending1, job_task) - table.insert(procs_pending1, job_proc_or_errors) - table.insert(indices_pending1, index) - else - table.insert(tasks_pending2, job_task) - table.insert(indices_pending2, index) - end - end - - -- next index - index = index + 1 - end - - -- merge pending tasks - procs = procs_pending1 - tasks = table.join(tasks_pending1, tasks_pending2) - indices = table.join(indices_pending1, indices_pending2) - - until #tasks == 0 - - -- ok - return true -end - -- return module: process return process diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 05bd99208..a7e99e8c6 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -33,6 +33,7 @@ local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") local environment = require("platform/environment") local package = require("package/package") +local import = require("sandbox/modules/import") -- load project function sandbox_core_project.load() @@ -92,7 +93,8 @@ function sandbox_core_project.check() end -- check all options - local ok, errors = process.runjobs(instance:fork(checktask):script(), #options, 4) + local runjobs = import("private.async.runjobs", {anonymous = true}) + local ok, errors = true--utils.trycall(runjobs, "check_options", instance:fork(checktask):script(), #options, 4) if not ok then raise(errors) end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index 904fe3119..0e5d500b2 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -33,6 +33,7 @@ local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") local cache = require("sandbox/modules/import/lib/detect/cache") +local scheduler = require("sandbox/modules/import/core/base/scheduler") -- globals local checking = nil @@ -238,11 +239,11 @@ end function sandbox_lib_detect_find_program.main(name, opt) -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache) - local coroutine_running = coroutine.running() + local coroutine_running = scheduler.co_running() if coroutine_running then while checking ~= nil and checking == name do local curdir = os.curdir() - coroutine.yield() + scheduler.co_yield() os.cd(curdir) end end diff --git a/xmake/core/sandbox/modules/process.lua b/xmake/core/sandbox/modules/process.lua index 92aa380de..de46625a1 100644 --- a/xmake/core/sandbox/modules/process.lua +++ b/xmake/core/sandbox/modules/process.lua @@ -139,15 +139,5 @@ function sandbox_process.asyncrun(task, waitchars) end end --- run jobs with processes -function sandbox_process.runjobs(jobfunc, total, comax, timeout, timer) - - -- run them - local ok, errors = process.runjobs(jobfunc, total, comax, timeout, timer) - if not ok then - raise(errors) - end -end - -- return module return sandbox_process diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua index e07c89923..60799c667 100644 --- a/xmake/modules/lib/detect/features.lua +++ b/xmake/modules/lib/detect/features.lua @@ -20,6 +20,7 @@ -- imports import("lib.detect.find_tool") +import("core.base.scheduler") -- get all features of the current tool -- @@ -57,11 +58,11 @@ function main(name, opt) local results = _g._RESULTS -- @note avoid detect the same program in the same time if running in the coroutine (e.g. ccache) - local coroutine_running = coroutine.running() + local coroutine_running = scheduler.co_running() if coroutine_running then while _g._checking ~= nil and _g._checking == key do local curdir = os.curdir() - coroutine.yield() + scheduler.co_yield() os.cd(curdir) end end diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index 1bb96e21d..1abf466a7 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.scheduler") import("core.project.config") import("lib.detect.cache") import("lib.detect.find_tool") @@ -74,11 +75,11 @@ function main(name, flags, opt) local key = plat .. "_" .. arch .. "_" .. tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(opt.sysflags, " ") .. "_" .. opt.flagskey -- @note avoid detect the same program in the same time if running in the coroutine (e.g. ccache) - local coroutine_running = coroutine.running() + local coroutine_running = scheduler.co_running() if coroutine_running then while _g._checking ~= nil and _g._checking == key do local curdir = os.curdir() - coroutine.yield() + scheduler.co_yield() os.cd(curdir) end end diff --git a/xmake/modules/net/ping.lua b/xmake/modules/net/ping.lua index 3db973c38..0af576081 100644 --- a/xmake/modules/net/ping.lua +++ b/xmake/modules/net/ping.lua @@ -22,6 +22,7 @@ import("lib.detect.cache") import("detect.tools.find_ping") import("detect.tools.find_nmap") +import("private.async.runjobs") -- send ping to hosts -- @@ -50,7 +51,7 @@ function main(hosts, opt) -- run tasks local results = {} hosts = table.wrap(hosts) - process.runjobs(function (index) + runjobs("ping", function (index) local host = hosts[index] if host then diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 0f71c2ddf..6a4fddd11 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -24,6 +24,7 @@ import("core.theme.theme") import("core.tool.compiler") import("core.project.depend") import("private.tools.ccache") +import("private.async.runjobs") -- do build file function _do_build_file(target, sourcefile, opt) @@ -132,7 +133,7 @@ function main(target, sourcebatch, opt) -- run build jobs for each source file local curdir = os.curdir() - process.runjobs(function (index) + runjobs("build_objects", function (index) -- force to set the current directory first because the other jobs maybe changed it os.cd(curdir) |
