summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-05 00:58:04 +0800
committerruki <[email protected]>2025-11-07 15:01:57 +0800
commit1e21a94d7bf8dad3eff10888458dfc7f1be39b11 (patch)
tree3a4352b32c452bc39b3c914a275da2621b9dddea
parent31d4f431d8267f3dfd52fae8184d09cc8c7f2529 (diff)
fix wait thread
-rw-r--r--xmake/core/base/thread.lua19
1 files changed, 11 insertions, 8 deletions
diff --git a/xmake/core/base/thread.lua b/xmake/core/base/thread.lua
index 26a6e2c52..1586882dd 100644
--- a/xmake/core/base/thread.lua
+++ b/xmake/core/base/thread.lua
@@ -182,7 +182,7 @@ function _thread:wait(timeout)
local ok, errors
local rpipe = self._RPIPE
- if rpipe and scheduler:co_running() then
+ if rpipe then
local buff = bytes(16)
local read, data_or_errors = rpipe:read(buff, 1, {block = true, timeout = timeout})
if read > 0 then
@@ -191,8 +191,13 @@ function _thread:wait(timeout)
ok = read
errors = data_or_errors
end
- else
- ok, errors = thread.thread_wait(self:cdata(), timeout)
+ end
+ if not scheduler:co_running() then
+ local waitok, wait_errors = thread.thread_wait(self:cdata(), timeout)
+ if ok == nil or ok > 0 then
+ ok = waitok
+ errors = wait_errors
+ end
end
if ok < 0 then
return -1, errors or string.format("%s: failed to resume thread!", self)
@@ -914,11 +919,9 @@ function thread._run_thread(callback_str, callinfo_str)
-- thread is finished, we need to notify the waited thread
if wpipe then
- if scheduler:co_running() then
- local ok, errors = wpipe:write("1", {block = true})
- if ok < 0 then
- return false, errors
- end
+ local ok, errors = wpipe:write("1", {block = true})
+ if ok < 0 then
+ return false, errors
end
wpipe:close()
end