summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-27 21:05:37 +0800
committerruki <[email protected]>2025-08-28 11:35:53 +0800
commitec3153a9254fb8d3f93371b4026dc1000afcae7c (patch)
tree45fca4689027f004f575a3bc821e25d5dfb5a4f9
parent9de0be5040e3feda8aface1174cd1e6fc696fe4e (diff)
move run_thread
-rw-r--r--xmake/core/main.lua29
-rw-r--r--xmake/core/thread/thread.lua36
2 files changed, 33 insertions, 32 deletions
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 826a2c3d8..62ca3de1d 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -41,7 +41,7 @@ local project = require("project/project")
local localcache = require("cache/localcache")
local profiler = require("base/profiler")
local debugger = require("base/debugger")
-local sandbox = require("sandbox/sandbox")
+local thread = require("thread/thread")
-- init the option menu
local menu =
@@ -275,31 +275,6 @@ function main._run_task(taskname)
return true
end
--- run thread
-function main._run_thread(callinfo_str)
-
- -- get callback info
- local callinfo, errors = string.deserialize(callinfo_str)
- if not callinfo then
- return false, string.format("invalid thread callinfo, %s!", errors or "unknown")
- end
- local callback = callinfo.callback
- if not callback then
- return false, string.format("no callback")
- end
-
- -- bind sandbox
--- local sandbox_inst, errors = sandbox.new(callback, {
--- filter = interp:filter(), rootdir = interp:rootdir(), namespace = interp:namespace()})
- local sandbox_inst, errors = sandbox.new(callback)
- if not sandbox_inst then
- return false, errors
- end
-
- -- do callback
- return sandbox.load(sandbox_inst:script(), table.unpack(callinfo.argv or {}))
-end
-
-- the main entry function
function main.entry()
@@ -362,7 +337,7 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
-- run task or thread
local thread_callinfo = xmake._THREAD_CALLINFO
if thread_callinfo then
- ok, errors = main._run_thread(thread_callinfo)
+ ok, errors = thread._run_thread(thread_callinfo)
else
ok, errors = main._run_task(option.taskname() or "build")
end
diff --git a/xmake/core/thread/thread.lua b/xmake/core/thread/thread.lua
index 33ac3dca0..9571c981b 100644
--- a/xmake/core/thread/thread.lua
+++ b/xmake/core/thread/thread.lua
@@ -23,11 +23,12 @@ local thread = thread or {}
local _instance = _instance or {}
-- load modules
-local io = require("base/io")
-local libc = require("base/libc")
-local bytes = require("base/bytes")
-local table = require("base/table")
-local string = require("base/string")
+local io = require("base/io")
+local libc = require("base/libc")
+local bytes = require("base/bytes")
+local table = require("base/table")
+local string = require("base/string")
+local sandbox = require("sandbox/sandbox")
-- the thread status
thread.STATUS_READY = 1
@@ -201,6 +202,31 @@ function thread.running()
-- TODO
end
+-- run thread
+function thread._run_thread(callinfo_str)
+
+ -- get callback info
+ local callinfo, errors = string.deserialize(callinfo_str)
+ if not callinfo then
+ return false, string.format("invalid thread callinfo, %s!", errors or "unknown")
+ end
+ local callback = callinfo.callback
+ if not callback then
+ return false, string.format("no callback")
+ end
+
+ -- bind sandbox
+-- local sandbox_inst, errors = sandbox.new(callback, {
+-- filter = interp:filter(), rootdir = interp:rootdir(), namespace = interp:namespace()})
+ local sandbox_inst, errors = sandbox.new(callback)
+ if not sandbox_inst then
+ return false, errors
+ end
+
+ -- do callback
+ return sandbox.load(sandbox_inst:script(), table.unpack(callinfo.argv or {}))
+end
+
-- return module
return thread