From 08fade0d0b92ed766da0f752d375eda1126291f8 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 19 Mar 2025 23:29:19 +0800 Subject: add build job queue stub --- xmake/modules/async/jobgraph.lua | 55 ++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua index 313bc2d11..612e56dee 100644 --- a/xmake/modules/async/jobgraph.lua +++ b/xmake/modules/async/jobgraph.lua @@ -25,7 +25,23 @@ import("core.base.graph") -- define module local jobqueue = jobqueue or object {_init = {"_jobgraph"}} -local jobgraph = jobgraph or object {_init = {"_jobs", "_graph", "_dirty"}} +local jobgraph = jobgraph or object {_init = {"_jobs", "_size", "_deps", "_dirty"}} + +-- build the job queue +function jobqueue:_build() + local graph = self._jobgraph + -- TODO + print("build job queue") +end + +-- update the job queue +function jobqueue:_update() + local graph = self._jobgraph + if graph._dirty then + self:_build() + graph._dirty = false + end +end -- remove the given job from the job queue function jobqueue:remove(job) @@ -33,11 +49,9 @@ end -- get a free job from the job queue function jobqueue:getfree() -end --- get jobs -function jobgraph:jobs() - return self._jobs + -- update the job queue first + self:_update() end -- add a job to the jobgraph @@ -51,23 +65,37 @@ end -- @param opt the job options -- function jobgraph:add(name, run, opt) - local job = {name = name, run = run, opt = opt} - self:jobs():insert(job) - self._dirty = true + local jobs = self._jobs + if not jobs[name] then + local job = {name = name, run = run, opt = opt} + jobs[name] = job + self._size = self._size + 1 + self._dirty = true + end end -- remove a given job function jobgraph:remove(name) - self._dirty = true + local jobs = self._jobs + if jobs[name] then + assert(self._size > 0) + jobs[name] = nil + self._size = self._size - 1 + self._dirty = true + end end -- add job deps, e.g. add_deps(a, b, c, ...): a -> b -> c, ... function jobgraph:add_deps(...) + -- TODO local deps = table.pack(...) + self._dirty = true end -- add jog group function jobgraph:add_group(name, callback) + -- TODO + self._dirty = true end -- build a job queue @@ -75,9 +103,14 @@ function jobgraph:build() return jobqueue {self} end +-- get jobs +function jobgraph:jobs() + return self._jobs +end + -- get job size function jobgraph:size() - return self:jobs():size() + return self._size end -- tostring @@ -87,5 +120,5 @@ end -- new a jobgraph function new() - return jobgraph {list.new(), graph.new(true), false} + return jobgraph {{}, 0, graph.new(true), false} end -- cgit v1.3.1