diff options
| author | ruki <[email protected]> | 2025-09-24 23:56:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-09-24 23:56:42 +0800 |
| commit | 80473173e753bc989f0b6ae216df160eff4e3911 (patch) | |
| tree | 4b0a99c9a9be6abe48c851851e79be3e670acccb | |
| parent | 708d5964ee9cf1325892dff5f1c1c47f2a202bb1 (diff) | |
improve to cache envs for scheduler
| -rw-r--r-- | xmake/core/base/scheduler.lua | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 9084ad6ba..fc6666c77 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -296,22 +296,15 @@ function scheduler:_co_curenvs_update(envs) return end - -- save the current directory hash - local envs_hash = "" + -- save the current environments envs = envs or os.getenvs() - for _, key in ipairs(table.orderkeys(envs)) do - envs_hash = envs_hash .. key:upper() .. envs[key] - end - envs_hash = hash.uuid4(envs_hash):sub(1, 8) - self._CO_CURENVS_HASH = envs_hash - - -- save the current directory for each coroutine local co_curenvs = self._CO_CURENVS if not co_curenvs then co_curenvs = {} self._CO_CURENVS = co_curenvs end - co_curenvs[running] = {envs_hash, envs} + co_curenvs[running] = envs + self._CO_CURENVS_CURRENT = envs end -- resume it's waiting coroutine if all coroutines are dead in group @@ -451,10 +444,10 @@ function scheduler:co_resume(co, ...) end -- has the current environments been changed? restore it - local curenvs = self._CO_CURENVS_HASH + local curenvs = self._CO_CURENVS_CURRENT local oldenvs = self._CO_CURENVS and self._CO_CURENVS[running] or nil - if oldenvs and curenvs ~= oldenvs[1] and running:is_isolated() then -- hash changed? - os.setenvs(oldenvs[2]) + if oldenvs and curenvs ~= oldenvs and running:is_isolated() then -- hash changed? + os.setenvs(oldenvs) end end @@ -476,10 +469,10 @@ function scheduler:co_suspend(...) end -- has the current environments been changed? restore it - local curenvs = self._CO_CURENVS_HASH + local curenvs = self._CO_CURENVS_CURRENT local oldenvs = self._CO_CURENVS and self._CO_CURENVS[running] or nil - if oldenvs and curenvs ~= oldenvs[1] and running:is_isolated() then -- hash changed? - os.setenvs(oldenvs[2]) + if oldenvs and curenvs ~= oldenvs and running:is_isolated() then -- hash changed? + os.setenvs(oldenvs) end -- return results |
