From fba862bb13f8780dd01ce85be8ac7c5709289b6d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 25 Jan 2024 00:44:24 +0800 Subject: lock and unlock coroutine #4645 --- xmake/modules/lib/detect/has_flags.lua | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'xmake/modules/lib/detect/has_flags.lua') diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index dc11db11c..e45a7a5b3 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -80,14 +80,6 @@ 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 - -- attempt to get result from cache first local cacheinfo = detectcache:get("lib.detect.has_flags") if not cacheinfo then @@ -101,6 +93,10 @@ function main(name, flags, opt) 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) @@ -122,7 +118,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 +128,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 +150,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 -- cgit v1.3.1