summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-27 23:23:00 +0800
committerruki <[email protected]>2025-08-28 11:35:54 +0800
commit6809e2d887d3f3f298b4e324a7580c55ac47562d (patch)
tree38d2ca2a0595636e0f5f12ab57d1516992049f3b
parent7bf08a61f291294d0dc021be62dec253146115f1 (diff)
move thread to base
m---------core/src/tbox/tbox0
-rw-r--r--tests/modules/thread/mutex.lua11
-rw-r--r--tests/modules/thread/sleep.lua4
-rw-r--r--xmake/core/base/thread.lua (renamed from xmake/core/thread/thread.lua)0
-rw-r--r--xmake/core/main.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/base/thread.lua (renamed from xmake/core/sandbox/modules/import/core/thread/thread.lua)42
6 files changed, 29 insertions, 30 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 7af204577394bb0364eef245f33e7cea6eed059
+Subproject 91a110d061d6486a7a0826919e0c60caf7586a3
diff --git a/tests/modules/thread/mutex.lua b/tests/modules/thread/mutex.lua
index 472b228db..0f1954c8a 100644
--- a/tests/modules/thread/mutex.lua
+++ b/tests/modules/thread/mutex.lua
@@ -1,8 +1,7 @@
-import("core.thread.thread")
-import("core.thread.mutex")
+import("core.base.thread")
function callback(mutex)
- import("core.thread.thread")
+ import("core.base.thread")
print("%s: starting ..", thread.running())
local dt = os.mclock()
for i = 1, 10 do
@@ -16,9 +15,9 @@ function callback(mutex)
end
function main()
- local m = mutex.new()
- local t0 = thread.start_named("thread_0", callback, m)
- local t1 = thread.start_named("thread_1", callback, m)
+ local mutex = thread.mutex()
+ local t0 = thread.start_named("thread_0", callback, mutex)
+ local t1 = thread.start_named("thread_1", callback, mutex)
t0:wait(-1)
t1:wait(-1)
end
diff --git a/tests/modules/thread/sleep.lua b/tests/modules/thread/sleep.lua
index 294c04fea..2e21aa3d2 100644
--- a/tests/modules/thread/sleep.lua
+++ b/tests/modules/thread/sleep.lua
@@ -1,7 +1,7 @@
-import("core.thread.thread")
+import("core.base.thread")
function callback(id)
- import("core.thread.thread")
+ import("core.base.thread")
print("%s: %d starting ..", thread.running(), id)
local dt = os.mclock()
for i = 1, 10 do
diff --git a/xmake/core/thread/thread.lua b/xmake/core/base/thread.lua
index bdf1c0380..bdf1c0380 100644
--- a/xmake/core/thread/thread.lua
+++ b/xmake/core/base/thread.lua
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index d1b1112a0..3f0a4484f 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 thread = require("thread/thread")
+local thread = require("base/thread")
-- init the option menu
local menu =
diff --git a/xmake/core/sandbox/modules/import/core/thread/thread.lua b/xmake/core/sandbox/modules/import/core/base/thread.lua
index f90ec339f..f56466ddf 100644
--- a/xmake/core/sandbox/modules/import/core/thread/thread.lua
+++ b/xmake/core/sandbox/modules/import/core/base/thread.lua
@@ -21,25 +21,25 @@
-- load modules
local utils = require("base/utils")
local string = require("base/string")
-local thread = require("thread/thread")
+local thread = require("base/thread")
local raise = require("sandbox/modules/raise")
-- define module
-local sandbox_core_thread = sandbox_core_thread or {}
-local sandbox_core_thread_instance = sandbox_core_thread_instance or {}
+local sandbox_core_base_thread = sandbox_core_base_thread or {}
+local sandbox_core_base_thread_instance = sandbox_core_base_thread_instance or {}
-- export the thread status
-sandbox_core_thread.STATUS_READY = thread.STATUS_READY
-sandbox_core_thread.STATUS_RUNNING = thread.STATUS_RUNNING
-sandbox_core_thread.STATUS_SUSPENDED = thread.STATUS_SUSPENDED
-sandbox_core_thread.STATUS_DEAD = thread.STATUS_DEAD
+sandbox_core_base_thread.STATUS_READY = thread.STATUS_READY
+sandbox_core_base_thread.STATUS_RUNNING = thread.STATUS_RUNNING
+sandbox_core_base_thread.STATUS_SUSPENDED = thread.STATUS_SUSPENDED
+sandbox_core_base_thread.STATUS_DEAD = thread.STATUS_DEAD
-- wrap thread
function _thread_wrap(instance)
-- hook thread interfaces
local hooked = {}
- for name, func in pairs(sandbox_core_thread_instance) do
+ for name, func in pairs(sandbox_core_base_thread_instance) do
if not name:startswith("_") and type(func) == "function" then
hooked["_" .. name] = instance["_" .. name] or instance[name]
hooked[name] = func
@@ -52,7 +52,7 @@ function _thread_wrap(instance)
end
-- start thread
-function sandbox_core_thread_instance.start(instance)
+function sandbox_core_base_thread_instance.start(instance)
local ok, errors = instance:_start()
if not ok then
raise(errors)
@@ -61,7 +61,7 @@ function sandbox_core_thread_instance.start(instance)
end
-- suspend thread
-function sandbox_core_thread_instance.suspend(instance)
+function sandbox_core_base_thread_instance.suspend(instance)
local ok, errors = instance:_suspend()
if not ok then
raise(errors)
@@ -69,7 +69,7 @@ function sandbox_core_thread_instance.suspend(instance)
end
-- resume thread
-function sandbox_core_thread_instance.resume(instance)
+function sandbox_core_base_thread_instance.resume(instance)
local ok, errors = instance:_resume()
if not ok then
raise(errors)
@@ -77,7 +77,7 @@ function sandbox_core_thread_instance.resume(instance)
end
-- wait thread
-function sandbox_core_thread_instance.wait(instance, timeout)
+function sandbox_core_base_thread_instance.wait(instance, timeout)
local ok, errors = instance:_wait(timeout)
if ok < 0 then
raise(errors)
@@ -85,7 +85,7 @@ function sandbox_core_thread_instance.wait(instance, timeout)
end
-- new thread
-function sandbox_core_thread.new(callback, opt)
+function sandbox_core_base_thread.new(callback, opt)
local instance, errors = thread.new(callback, opt)
if not instance then
raise(errors)
@@ -94,22 +94,22 @@ function sandbox_core_thread.new(callback, opt)
end
-- start a thread
-function sandbox_core_thread.start(callback, ...)
- return sandbox_core_thread.start_withopt(callback, {argv = table.pack(...)})
+function sandbox_core_base_thread.start(callback, ...)
+ return sandbox_core_base_thread.start_withopt(callback, {argv = table.pack(...)})
end
-- start a named thread
-function sandbox_core_thread.start_named(name, callback, ...)
- return sandbox_core_thread.start_withopt(callback, {name = name, argv = table.pack(...)})
+function sandbox_core_base_thread.start_named(name, callback, ...)
+ return sandbox_core_base_thread.start_withopt(callback, {name = name, argv = table.pack(...)})
end
-- start a thread with options
-function sandbox_core_thread.start_withopt(callback, opt)
- return sandbox_core_thread.new(callback, opt):start()
+function sandbox_core_base_thread.start_withopt(callback, opt)
+ return sandbox_core_base_thread.new(callback, opt):start()
end
-- get the running thread
-function sandbox_core_thread.running()
+function sandbox_core_base_thread.running()
local instance, errors = thread.running()
if not instance then
raise(errors)
@@ -118,5 +118,5 @@ function sandbox_core_thread.running()
end
-- return module
-return sandbox_core_thread
+return sandbox_core_base_thread