summaryrefslogtreecommitdiff
path: root/xmake/core/thread/thread.lua
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 /xmake/core/thread/thread.lua
parent9de0be5040e3feda8aface1174cd1e6fc696fe4e (diff)
move run_thread
Diffstat (limited to 'xmake/core/thread/thread.lua')
-rw-r--r--xmake/core/thread/thread.lua36
1 files changed, 31 insertions, 5 deletions
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