diff options
| author | ruki <[email protected]> | 2016-07-13 10:19:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-13 10:19:43 +0800 |
| commit | ad41572d133d11d74e12d37e57d496aa26fe76db (patch) | |
| tree | 531322956699aff2365ce3111e5ea5c64b9e9ba0 | |
| parent | c0f02d4654ea2b46732eacbacce8fc9ee80c6e9a (diff) | |
rewrite scheduling for compiling
| -rw-r--r-- | core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/xmake/process/waitlist.c | 12 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 87 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/process.lua | 5 |
5 files changed, 75 insertions, 35 deletions
diff --git a/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h b/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h index 050b08d4f..ed5554f14 100644 --- a/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h +++ b/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h @@ -6,7 +6,7 @@ #define TB_CONFIG_VERSION_MAJOR 1
#define TB_CONFIG_VERSION_MINOR 5
#define TB_CONFIG_VERSION_ALTER 3
-#define TB_CONFIG_VERSION_BUILD 201607050901
+#define TB_CONFIG_VERSION_BUILD 201607130958
// defines
#define TB_CONFIG_OS_WINDOWS 1
diff --git a/core/src/xmake/process/waitlist.c b/core/src/xmake/process/waitlist.c index a2d461401..98fd438e3 100755 --- a/core/src/xmake/process/waitlist.c +++ b/core/src/xmake/process/waitlist.c @@ -45,9 +45,9 @@ * failed: -1 * * for _, procinfo in ipairs(list) do - * print("index: ", procinfo[1]) - * print("status: ", procinfo[2]) - * print("process: ", procinfo[3]) + * print("proc: ", procinfo[1]) + * print("index: ", procinfo[2]) + * print("status: ", procinfo[3]) * end */ tb_int_t xm_process_waitlist(lua_State* lua) @@ -126,11 +126,11 @@ tb_int_t xm_process_waitlist(lua_State* lua) { // save one process info lua_newtable(lua); - lua_pushinteger(lua, infolist[i].index + 1); + lua_pushlightuserdata(lua, infolist[i].process); lua_rawseti(lua, -2, 1); - lua_pushinteger(lua, infolist[i].status); + lua_pushinteger(lua, infolist[i].index + 1); lua_rawseti(lua, -2, 2); - lua_pushlightuserdata(lua, infolist[i].process); + lua_pushinteger(lua, infolist[i].status); lua_rawseti(lua, -2, 3); lua_rawseti(lua, -2, i + 1); diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 5cfaf7cf5..aab181c0b 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -154,45 +154,88 @@ function buildall(target, g) local index = 1 local total = #target:objectfiles() local tasks = {} + local procs = {} repeat - -- consume tasks - local pendings = {} - for i, task in ipairs(tasks) do + -- wait processes + local tasks_finished = {} + local procs_count = #procs + if procs_count > 0 then - -- get job - local job = task[1] + -- wait them + local procinfos = process.waitlist(procs, ifelse(procs_count < jobs, 0, -1)) + for _, procinfo in ipairs(procinfos) do + + -- the process info + local proc = procinfo[1] + local procid = procinfo[2] + local status = procinfo[3] - -- get job index - local job_index = task[2] + -- check + assert(procs[procid] == proc) - -- pending? - local status = coroutine.status(job) - if status ~= "dead" then + -- resume this task + local job_task = tasks[procid] + local job_proc = coroutine.resume(job_task, 1, status) - -- resume it - coroutine.resume(job, job_index) + -- the other process is pending for this task? + if coroutine.status(job_task) ~= "dead" then - -- append the pending task - table.insert(pendings, task) + -- check + assert(job_proc) + + -- update the pending process + procs[procid] = job_proc + + -- this task has been finised? + else + + -- mark this task as finised + tasks_finished[procid] = true + end end end - -- update the pending tasks - tasks = pendings + -- update the pending tasks and procs + local tasks_pending = {} + local procs_pending = {} + for taskid, job_task in ipairs(tasks) do + if not tasks_finished[taskid] then + table.insert(tasks_pending, job_task) + table.insert(procs_pending, procs[taskid]) + end + end + tasks = tasks_pending + procs = procs_pending -- produce tasks local curdir = os.curdir() while #tasks < jobs and index <= total do - table.insert(tasks, {coroutine.create(function (index) - -- force to set the current directory first because the other jobs maybe changed it - os.cd(curdir) + -- new task + local job_task = coroutine.create(function (index) + + -- force to set the current directory first because the other jobs maybe changed it + os.cd(curdir) - -- build object - _build(target, g, index) + -- build object + _build(target, g, index) + + end) + + -- resume it first + local job_proc = coroutine.resume(job_task, index) + if coroutine.status(job_task) ~= "dead" then + + -- check + assert(job_proc) + + -- put task and proc to the pendings tasks + table.insert(tasks, job_task) + table.insert(procs, job_proc) + end - end), index}) + -- next index index = index + 1 end diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ae93103eb..cf662aab3 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -327,7 +327,7 @@ function os.exec(cmd, outfile, errfile) -- poll it waitok, status = process.wait(proc, 0) if waitok == 0 then - coroutine.yield() + waitok, status = coroutine.yield(proc) end until waitok ~= 0 @@ -371,7 +371,7 @@ function os.execv(shellname, argv, outfile, errfile) -- poll it waitok, status = process.wait(proc, 0) if waitok == 0 then - coroutine.yield() + waitok, status = coroutine.yield(proc) end until waitok ~= 0 diff --git a/xmake/core/sandbox/modules/process.lua b/xmake/core/sandbox/modules/process.lua index 12ae20fad..28d814078 100644 --- a/xmake/core/sandbox/modules/process.lua +++ b/xmake/core/sandbox/modules/process.lua @@ -121,11 +121,8 @@ function sandbox_process.waitlist(processes, timeout) raise("wait processes(%d) failed(%d)", #processes, count) end - -- check infos - assert(infos and count == #infos) - -- timeout or finished - return count, infos + return infos end -- return module |
