diff options
| author | ruki <[email protected]> | 2025-11-03 22:48:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-07 15:01:56 +0800 |
| commit | fa6b4470bd96c8f23133b43ba563af1a25c04a11 (patch) | |
| tree | edee660393625343e96cce51bc3ebb9eb4939487 | |
| parent | 85980580cf9fab96edda2325b59fb315fed4a7ce (diff) | |
fix async thread
| -rw-r--r-- | xmake/core/base/os.lua | 18 | ||||
| -rw-r--r-- | xmake/core/base/private/async_task.lua | 12 | ||||
| -rw-r--r-- | xmake/core/base/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/cache/build_cache.lua | 2 |
5 files changed, 27 insertions, 12 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 7b573169d..94cde85e7 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -522,7 +522,7 @@ function os.cp(srcpath, dstpath, opt) end -- do it in the asynchronous task - if opt and opt.async then + if opt and opt.async and xmake.in_main_thread() then return os._async_task().cp(srcpath, dstpath, {detach = opt.detach}) end @@ -587,8 +587,8 @@ function os.rm(filepath, opt) end -- do it in the asynchronous task - if opt.async then - return os._async_task().rm(filepath, {detach = opt.detach}) + if opt.async and xmake.in_main_thread() then + return os._async_task().rm(filepath, {detach = opt.detach}) end -- remove file or directories @@ -710,7 +710,7 @@ function os.rmdir(dir, opt) end -- do it in the asynchronous task - if opt and opt.async then + if opt and opt.async and xmake.in_main_thread() then return os._async_task().rmdir(dir, {detach = opt.detach}) end @@ -861,16 +861,14 @@ function os.runv(program, argv, opt) end -- remove the temporary log file - os.rm(logfile) + os.rm(logfile, {async = true, detach = true}) -- failed return false, errors end -- remove the temporary log file - os.rm(logfile) - - -- ok + os.rm(logfile, {async = true, detach = true}) return true end @@ -1093,8 +1091,8 @@ function os.iorunv(program, argv, opt) local errdata = io.readfile(errfile) -- remove the temporary output and error file - os.rm(outfile) - os.rm(errfile) + os.rm(outfile, {async = true, detach = true}) + os.rm(errfile, {async = true, detach = true}) return ok == 0, outdata, errdata, errors end diff --git a/xmake/core/base/private/async_task.lua b/xmake/core/base/private/async_task.lua index 1356072e5..a6116c5a0 100644 --- a/xmake/core/base/private/async_task.lua +++ b/xmake/core/base/private/async_task.lua @@ -135,6 +135,10 @@ function async_task.cp(srcpath, dstpath, opt) return false, errors end + -- TODO + assert(opt.detach) + + -- post task srcpath = path.absolute(tostring(srcpath)) dstpath = path.absolute(tostring(dstpath)) task_queue:push({kind = "cp", srcpath = srcpath, dstpath = dstpath}) @@ -150,6 +154,10 @@ function async_task.rm(filepath, opt) return false, errors end + -- TODO + assert(opt.detach) + + -- post task filepath = path.absolute(tostring(filepath)) task_queue:push({kind = "rm", filepath = filepath}) task_event:post() @@ -164,6 +172,10 @@ function async_task.rmdir(dir, opt) return false, errors end + -- TODO + assert(opt.detach) + + -- post task dir = path.absolute(tostring(dir)) task_queue:push({kind = "rmdir", dir = dir}) task_event:post() diff --git a/xmake/core/base/xmake.lua b/xmake/core/base/xmake.lua index 2b41e9a9d..d25e60147 100644 --- a/xmake/core/base/xmake.lua +++ b/xmake/core/base/xmake.lua @@ -67,6 +67,11 @@ function xmake.is_embed() return xmake._EMBED or false end +-- in main thread? +function xmake.in_main_thread() + return xmake._THREAD_CALLBACK == nil +end + -- get command arguments function xmake.argv() return xmake._ARGV diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 6d5f59fac..b141ac5ab 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -1070,7 +1070,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) end -- remove the temporary dependent file - os.tryrm(depfile) + os.tryrm(depfile, {async = true, detach = true}) end end } diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index d3c0094d8..573d94550 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -339,7 +339,7 @@ function build(program, argv, opt) _g.cache_miss_total_time = (_g.cache_miss_total_time or 0) + (os.mclock() - cache_miss_start_time) end end - os.rm(cppinfo.cppfile) + os.tryrm(cppinfo.cppfile, {async = true, detach = true}) else _g.preprocess_error_count = (_g.preprocess_error_count or 0) + 1 end |
