summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-05 00:57:48 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commitf48d5e6837c0039651385f409c8f3fc8188e086b (patch)
tree461baae6a5785197c1b3faf937986ef9ea9af6b0
parent71e29f82a04a6a799997eda741c318969c57354b (diff)
improve runjobs to support timer
-rw-r--r--tests/modules/scheduler/runjobs.lua5
-rw-r--r--xmake/actions/require/impl/package.lua6
-rw-r--r--xmake/modules/private/async/runjobs.lua23
3 files changed, 29 insertions, 5 deletions
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
index 36f72b47f..73398d179 100644
--- a/tests/modules/scheduler/runjobs.lua
+++ b/tests/modules/scheduler/runjobs.lua
@@ -10,6 +10,9 @@ function _jobfunc(index)
end
function main()
- runjobs("test", _jobfunc, 100, 6)
+ local t = os.mclock()
+ runjobs("test", _jobfunc, 100, 6, 1000, function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end)
end
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 822dd59ed..9b1df68a2 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 (indices, tips)
+ end, #packages_install, (option.get("verbose") or option.get("diagnosis")) and 1 or 4, 300, function (running_jobs_indices)
-- do not print progress info if be verbose
if option.get("verbose") or not show_wait then
@@ -646,7 +646,7 @@ function _install_packages(packages_install, packages_download)
-- make installing and downloading packages list
local installing = {}
local downloading = {}
- for _, index in ipairs(indices) do
+ for _, index in ipairs(running_jobs_indices) do
local package = packages_installing[index]
if package then
table.insert(installing, package:name())
@@ -666,7 +666,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(" .. ${dim}%s${clear}%s", tips and (tips .. " ") or "", waitchars[waitindex + 1])
+ cprintf(" .. %s", waitchars[waitindex + 1])
io.flush()
end)
end
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 5205ef3ed..0c276afec 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -22,19 +22,40 @@
import("core.base.scheduler")
-- main entry
-function main(name, jobfunc, total, comax)
+function main(name, jobfunc, total, comax, timeout, timerfunc)
+ -- run timer
+ local stop = false
+ local running_jobs_indices
+ if timerfunc then
+ assert(timeout and timeout < 60000, "runjobs: invalid timer timeout!")
+ scheduler.co_start_named(name .. "/timer", function ()
+ while not stop do
+ os.sleep(timeout)
+ if not stop then
+ timerfunc(running_jobs_indices)
+ end
+ end
+ end)
+ end
+
+ -- 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 ()
local max = math.min(index + comax, total)
while index < max do
index = index + 1
+ table.insert(running_jobs_indices, index)
scheduler.co_start_named(name .. '/' .. tostring(index), jobfunc, index)
end
end)
scheduler.co_group_wait(group_name)
end
+
+ -- stop timer
+ stop = true
end