summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-19 23:35:27 +0800
committerruki <[email protected]>2025-04-08 15:31:54 +0800
commitbc4f14679956d6eac336cb23d72e5e91c189a5bf (patch)
tree6d08e7865066546e06abf1171318470494770be1
parenta588ee1c3f407cdfcbe5bc9753a5be1b7ca72e7e (diff)
add deps for jobgraph
-rw-r--r--tests/modules/async/run_jobgraph.lua2
-rw-r--r--xmake/modules/async/jobgraph.lua31
2 files changed, 25 insertions, 8 deletions
diff --git a/tests/modules/async/run_jobgraph.lua b/tests/modules/async/run_jobgraph.lua
index ec9c9175f..a3e1edeb3 100644
--- a/tests/modules/async/run_jobgraph.lua
+++ b/tests/modules/async/run_jobgraph.lua
@@ -11,7 +11,7 @@ function _jobfunc(index, total, opt)
end
function main()
- print("==================================== test jobpool ====================================")
+ print("==================================== test jobgraph ====================================")
local jobs = jobgraph.new()
jobs:add("job/root", _jobfunc)
for i = 1, 3 do
diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua
index 612e56dee..684b7d7d8 100644
--- a/xmake/modules/async/jobgraph.lua
+++ b/xmake/modules/async/jobgraph.lua
@@ -25,7 +25,7 @@ import("core.base.graph")
-- define module
local jobqueue = jobqueue or object {_init = {"_jobgraph"}}
-local jobgraph = jobgraph or object {_init = {"_jobs", "_size", "_deps", "_dirty"}}
+local jobgraph = jobgraph or object {_init = {"_name", "_jobs", "_size", "_deps", "_dirty"}}
-- build the job queue
function jobqueue:_build()
@@ -87,9 +87,21 @@ 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
+ local prev
+ local dirty
+ local jobs = self._jobs
+ local deps = self._deps
+ for _, name in ipairs(table.pack(...)) do
+ local curr = assert(jobs[name], "job(%s) not found in jobgraph(%s)", name, self)
+ if prev then
+ deps:add_edge(prev, curr)
+ dirty = true
+ end
+ prev = curr
+ end
+ if dirty then
+ self._dirty = true
+ end
end
-- add jog group
@@ -108,6 +120,11 @@ function jobgraph:jobs()
return self._jobs
end
+-- get jobgraph name
+function jobgraph:name()
+ return self._name
+end
+
-- get job size
function jobgraph:size()
return self._size
@@ -115,10 +132,10 @@ end
-- tostring
function jobgraph:__tostring()
- return string.format("<jobgraph:%s>", self:size())
+ return string.format("<jobgraph:%s/%d>", self:name() or "anonymous", self:size())
end
-- new a jobgraph
-function new()
- return jobgraph {{}, 0, graph.new(true), false}
+function new(name)
+ return jobgraph {name, {}, 0, graph.new(true), false}
end