summaryrefslogtreecommitdiff
path: root/xmake/core/base/process.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-05 00:39:54 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commit35b8b34362abe28a638af8ee02d3babe8e3548e2 (patch)
treea47c0a1da53fffd81f0aa7832ceb3646950bd08a /xmake/core/base/process.lua
parent94d3eb649e489a597a2f5d966d2249a9e64d87e3 (diff)
uses new runjobs
Diffstat (limited to 'xmake/core/base/process.lua')
-rw-r--r--xmake/core/base/process.lua142
1 files changed, 0 insertions, 142 deletions
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