summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-25 22:32:40 +0800
committerruki <[email protected]>2024-01-25 12:10:23 +0800
commit039897c33bf0e4066eaae3583d09721f46226a87 (patch)
tree9d8d6b9c79f6c68f26d86fe387a0d0638bbec96f
parentdbb46f95b4b61787857261807a741f8ae34db7f9 (diff)
improve to find_program
-rw-r--r--xmake/core/base/scheduler.lua8
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua9
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_programver.lua9
-rw-r--r--xmake/modules/lib/detect/features.lua9
-rw-r--r--xmake/modules/lib/detect/has_flags.lua9
5 files changed, 25 insertions, 19 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index ab2d349d6..003c17892 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -574,9 +574,11 @@ function scheduler:co_unlock(lockname)
local co_task = waiting_tasks[#waiting_tasks]
if co_task then
table.remove(waiting_tasks)
- local ok, errors = self:co_resume(co_task)
- if not ok then
- return false, errors
+ if co_task:is_suspended() then
+ local ok, errors = self:co_resume(co_task)
+ if not ok then
+ return false, errors
+ end
end
end
end
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 84cd061ad..a3264cb11 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -277,16 +277,17 @@ function sandbox_lib_detect_find_program.main(name, opt)
cachekey = cachekey .. "_" .. opt.cachekey
end
+ -- @see https://github.com/xmake-io/xmake/issues/4645
+ -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
+ scheduler.co_lock(cachekey)
+
-- attempt to get result from cache first
local result = detectcache:get2(cachekey, name)
if result ~= nil and not opt.force then
+ scheduler.co_unlock(cachekey)
return result and result or nil
end
- -- @see https://github.com/xmake-io/xmake/issues/4645
- -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
- scheduler.co_lock(cachekey)
-
-- get paths from the opt.envs.PATH
-- @note the wrong `pathes` word will be discarded, but the interface parameters will still be compatible
local envs = opt.envs
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
index 2d2c158d6..855a07479 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
@@ -61,16 +61,17 @@ function sandbox_lib_detect_find_programver.main(program, opt)
cachekey = cachekey .. "_" .. opt.cachekey
end
+ -- @see https://github.com/xmake-io/xmake/issues/4645
+ -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
+ scheduler.co_lock(cachekey)
+
-- attempt to get result from cache first
local result = detectcache:get2(cachekey, program)
if result ~= nil and not opt.force then
+ scheduler.co_unlock(cachekey)
return result and result or nil
end
- -- @see https://github.com/xmake-io/xmake/issues/4645
- -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
- scheduler.co_lock(cachekey)
-
-- attempt to get version output info
profiler:enter("find_programver", program)
local ok = false
diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua
index 33be29301..7a00b04b4 100644
--- a/xmake/modules/lib/detect/features.lua
+++ b/xmake/modules/lib/detect/features.lua
@@ -57,16 +57,17 @@ function main(name, opt)
_g._RESULTS = _g._RESULTS or {}
local results = _g._RESULTS
+ -- @see https://github.com/xmake-io/xmake/issues/4645
+ -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
+ scheduler.co_lock(key)
+
-- get result from the cache first
local result = results[key]
if result ~= nil then
+ scheduler.co_unlock(key)
return result
end
- -- @see https://github.com/xmake-io/xmake/issues/4645
- -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
- scheduler.co_lock(key)
-
-- detect.tools.xxx.features(opt)?
local features = import("detect.tools." .. tool.name .. ".features", {try = true})
if features then
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index e45a7a5b3..abfae3a57 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -80,6 +80,10 @@ function main(name, flags, opt)
.. (tool.version or "") .. "_" .. (opt.toolkind or "")
.. "_" .. (opt.flagkind or "") .. "_" .. table.concat(opt.sysflags, " ") .. "_" .. opt.flagskey
+ -- @see https://github.com/xmake-io/xmake/issues/4645
+ -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
+ scheduler.co_lock(key)
+
-- attempt to get result from cache first
local cacheinfo = detectcache:get("lib.detect.has_flags")
if not cacheinfo then
@@ -90,13 +94,10 @@ function main(name, flags, opt)
end
local result = cacheinfo[key]
if result ~= nil and not opt.force then
+ scheduler.co_unlock(key)
return result
end
- -- @see https://github.com/xmake-io/xmake/issues/4645
- -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache)
- scheduler.co_lock(key)
-
-- generate all checked flags
local checkflags = table.join(flags, opt.sysflags)