summaryrefslogtreecommitdiff
path: root/xmake/core/sandbox/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-29 23:20:48 +0800
committerruki <[email protected]>2025-08-29 23:20:48 +0800
commitf1d54d70a80b86465c2df36eb95a0bcda8c26824 (patch)
treea351724ed7b43246e21d20720b577557df764ba6 /xmake/core/sandbox/modules
parent054c5764447dc51081d466c1bc2e26fda5906712 (diff)
add thread sharedata
Diffstat (limited to 'xmake/core/sandbox/modules')
-rw-r--r--xmake/core/sandbox/modules/import/core/base/thread.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/core/base/thread.lua b/xmake/core/sandbox/modules/import/core/base/thread.lua
index a10dc1511..21e068964 100644
--- a/xmake/core/sandbox/modules/import/core/base/thread.lua
+++ b/xmake/core/sandbox/modules/import/core/base/thread.lua
@@ -31,6 +31,7 @@ local sandbox_core_base_thread_mutex = sandbox_core_base_thread_mutex or {}
local sandbox_core_base_thread_event = sandbox_core_base_thread_event or {}
local sandbox_core_base_thread_semaphore = sandbox_core_base_thread_semaphore or {}
local sandbox_core_base_thread_queue = sandbox_core_base_thread_queue or {}
+local sandbox_core_base_thread_sharedata = sandbox_core_base_thread_sharedata or {}
-- export the thread status
sandbox_core_base_thread.STATUS_READY = thread.STATUS_READY
@@ -215,6 +216,41 @@ function sandbox_core_base_thread_queue.close(queue)
end
end
+-- clear sharedata
+function sandbox_core_base_thread_sharedata.clear(sharedata)
+ local ok, errors = sharedata:_clear()
+ if not ok then
+ raise(errors)
+ end
+ return ok
+end
+
+-- set sharedata
+function sandbox_core_base_thread_sharedata.set(sharedata, value)
+ local ok, errors = sharedata:_set(value)
+ if not ok then
+ raise(errors)
+ end
+ return ok
+end
+
+-- get sharedata
+function sandbox_core_base_thread_sharedata.get(sharedata)
+ local value, errors = sharedata:_get()
+ if value == nil and errors then
+ raise(errors)
+ end
+ return value
+end
+
+-- close sharedata
+function sandbox_core_base_thread_sharedata.close(sharedata)
+ local ok, errors = sharedata:_close()
+ if not ok then
+ raise(errors)
+ end
+end
+
-- new thread
function sandbox_core_base_thread.new(callback, opt)
local instance, errors = thread.new(callback, opt)
@@ -332,6 +368,27 @@ function sandbox_core_base_thread.queue(name)
return queue
end
+-- open a sharedata
+function sandbox_core_base_thread.sharedata(name)
+ local sharedata, errors = thread.sharedata(name)
+ if not sharedata then
+ raise(errors)
+ end
+
+ -- hook filesharedata interfaces
+ local hooked = {}
+ for name, func in pairs(sandbox_core_base_thread_sharedata) do
+ if not name:startswith("_") and type(func) == "function" then
+ hooked["_" .. name] = sharedata["_" .. name] or sharedata[name]
+ hooked[name] = func
+ end
+ end
+ for name, func in pairs(hooked) do
+ sharedata[name] = func
+ end
+ return sharedata
+end
+
-- return module
return sandbox_core_base_thread