summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-05 22:30:09 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commit35ffc50b1dc6abc88586ac1986607db16772c686 (patch)
treeeebc6439f8c37391d3e528feae7e3f09ce274bc8
parentf48d5e6837c0039651385f409c8f3fc8188e086b (diff)
replace all runjobs
-rw-r--r--tests/modules/scheduler/runjobs.lua4
-rw-r--r--xmake/actions/build/kinds/object.lua5
-rw-r--r--xmake/actions/require/impl/package.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua2
-rw-r--r--xmake/modules/net/ping.lua2
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/async/runjobs.lua18
7 files changed, 22 insertions, 17 deletions
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
index 73398d179..7fea9bf66 100644
--- a/tests/modules/scheduler/runjobs.lua
+++ b/tests/modules/scheduler/runjobs.lua
@@ -11,8 +11,8 @@ end
function main()
local t = os.mclock()
- runjobs("test", _jobfunc, 100, 6, 1000, function (running_jobs_indices)
+ runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices)
print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
- end)
+ end})
end
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index ef2ddd51d..141019cf3 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
+import("private.async.runjobs")
-- build source files with the custom rule
function _build_files_with_rule(target, sourcebatch, opt, suffix)
@@ -57,7 +58,7 @@ function _build_files_with_rule(target, sourcebatch, opt, suffix)
-- run build jobs for each source file
local curdir = os.curdir()
local sourcecount = #sourcebatch.sourcefiles
- process.runjobs(function (index)
+ runjobs("build_files", function (index)
-- force to set the current directory first because the other jobs maybe changed it
os.cd(curdir)
@@ -76,7 +77,7 @@ function _build_files_with_rule(target, sourcebatch, opt, suffix)
-- do build file
on_build_file(target, sourcefile, {sourcekind = sourcebatch.sourcekind, progress = progress_now})
- end, sourcecount, jobs)
+ end, {total = sourcecount, comax = jobs})
end
end
end
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 9b1df68a2..beac43ec2 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -633,7 +633,7 @@ function _install_packages(packages_install, packages_download)
packages_installing[index] = nil
packages_downloading[index] = nil
- end, #packages_install, (option.get("verbose") or option.get("diagnosis")) and 1 or 4, 300, function (running_jobs_indices)
+ end, {total = #packages_install, comax = (option.get("verbose") or option.get("diagnosis")) and 1 or 4, timeout = 300, timer = function (running_jobs_indices)
-- do not print progress info if be verbose
if option.get("verbose") or not show_wait then
@@ -668,7 +668,7 @@ function _install_packages(packages_install, packages_download)
end
cprintf(" .. %s", waitchars[waitindex + 1])
io.flush()
- end)
+ end})
end
-- the cache directory
@@ -727,7 +727,7 @@ function install_packages(requires, opt)
package:fetch()
package:envs_leave()
end
- end, #packages)
+ end, {total = #packages})
-- filter packages
local packages_install = {}
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index a2aa82bd2..3f197f3b3 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -93,7 +93,7 @@ function sandbox_core_project.check()
end
-- check all options
- import("private.async.runjobs", {anonymous = true})("check_options", instance:fork(checktask):script(), #options, 4)
+ import("private.async.runjobs", {anonymous = true})("check_options", instance:fork(checktask):script(), {total = #options, comax = 4})
-- leave toolchains environment
environment.leave("toolchains")
diff --git a/xmake/modules/net/ping.lua b/xmake/modules/net/ping.lua
index 0af576081..6c9cf3f8f 100644
--- a/xmake/modules/net/ping.lua
+++ b/xmake/modules/net/ping.lua
@@ -107,7 +107,7 @@ function main(hosts, opt)
vprint("pinging for the host(%s) ... %d ms", host, timeval)
end
end
- end, #hosts)
+ end, {total = #hosts})
-- save cache
if cacheinfo then
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index 6a4fddd11..b2aec9c72 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -141,5 +141,5 @@ function main(target, sourcebatch, opt)
-- build object
_build_object(target, sourcebatch, index, opt)
- end, #sourcebatch.sourcefiles, jobs)
+ end, {total = #sourcebatch.sourcefiles, comax = jobs})
end
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 0c276afec..bc2be74ca 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -21,19 +21,24 @@
-- imports
import("core.base.scheduler")
--- main entry
-function main(name, jobfunc, total, comax, timeout, timerfunc)
+-- asynchronous run jobs
+function main(name, jobfunc, opt)
+
+ -- init options
+ op = opt or {}
+ local total = opt.total or 1
+ local comax = opt.comax or total
-- run timer
local stop = false
local running_jobs_indices
- if timerfunc then
- assert(timeout and timeout < 60000, "runjobs: invalid timer timeout!")
+ if opt.timer then
+ assert(opt.timeout and opt.timeout < 60000, "runjobs: invalid timer timeout!")
scheduler.co_start_named(name .. "/timer", function ()
while not stop do
- os.sleep(timeout)
+ os.sleep(opt.timeout)
if not stop then
- timerfunc(running_jobs_indices)
+ opt.timer(running_jobs_indices)
end
end
end)
@@ -42,7 +47,6 @@ function main(name, jobfunc, total, comax, timeout, timerfunc)
-- run jobs
local index = 0
local group_name = name
- comax = comax or total
while index < total do
running_jobs_indices = {}
scheduler.co_group_begin(group_name, function ()