diff options
| author | ruki <[email protected]> | 2024-01-28 23:13:00 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-28 23:13:00 +0800 |
| commit | 1d4a3e7645143f98ea1089b63153834f7c913d4b (patch) | |
| tree | 60ac1d7e55fbea740a0594ce0e81987886d1ccca /xmake/modules/lib/detect | |
| parent | f383a6e46a9072c639d6df97bba161b8ec6add7c (diff) | |
| parent | 2727f450c5bdbd5b440de5fb44d4afcb6fcea2eb (diff) | |
Merge pull request #4648 from xmake-io/co
lock and unlock coroutine #4645
Diffstat (limited to 'xmake/modules/lib/detect')
| -rw-r--r-- | xmake/modules/lib/detect/features.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 14 |
2 files changed, 10 insertions, 18 deletions
diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua index 8b9bde45b..7a00b04b4 100644 --- a/xmake/modules/lib/detect/features.lua +++ b/xmake/modules/lib/detect/features.lua @@ -57,29 +57,25 @@ function main(name, opt) _g._RESULTS = _g._RESULTS or {} local results = _g._RESULTS - -- @note avoid detect the same program in the same time if running in the coroutine (e.g. ccache) - local coroutine_running = scheduler.co_running() - if coroutine_running then - while _g._checking ~= nil and _g._checking == key do - scheduler.co_yield() - end - 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) -- get result from the cache first local result = results[key] if result ~= nil then + scheduler.co_unlock(key) return result end -- detect.tools.xxx.features(opt)? - _g._checking = coroutine_running and key or nil local features = import("detect.tools." .. tool.name .. ".features", {try = true}) if features then result = features(opt) end - _g._checking = nil result = result or {} results[key] = result + scheduler.co_unlock(key) return result end diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index dc11db11c..abfae3a57 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -80,13 +80,9 @@ function main(name, flags, opt) .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(opt.sysflags, " ") .. "_" .. opt.flagskey - -- @note avoid detect the same program in the same time if running in the coroutine (e.g. ccache) - local coroutine_running = scheduler.co_running() - if coroutine_running then - while _g._checking ~= nil and _g._checking == key do - scheduler.co_yield() - end - 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) -- attempt to get result from cache first local cacheinfo = detectcache:get("lib.detect.has_flags") @@ -98,6 +94,7 @@ 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 @@ -122,7 +119,6 @@ function main(name, flags, opt) profiler.enter("has_flags", tool.name, checkflags[1]) -- detect.tools.xxx.has_flags(flags, opt)? - _g._checking = coroutine_running and key or nil local hasflags = import("detect.tools." .. tool.name .. ".has_flags", {try = true}) local errors = nil if hasflags then @@ -133,7 +129,6 @@ function main(name, flags, opt) if opt.on_check then result, errors = opt.on_check(result, errors) end - _g._checking = nil result = result or false -- stop profile @@ -156,6 +151,7 @@ function main(name, flags, opt) cacheinfo[key] = result detectcache:set("lib.detect.has_flags", cacheinfo) detectcache:save() + scheduler.co_unlock(key) return result end |
