diff options
| author | Yong He <yonghe@outlook.com> | 2025-02-24 12:51:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-24 12:51:51 -0800 |
| commit | 9e465c776af22ff7a19818b1b135b9e5287aa603 (patch) | |
| tree | d102c731f6c6c614199aeb44cf4683b58c3268df /source/slang/slang.cpp | |
| parent | edcb2f0b8216f964f10ba60d96b8070fdc1ae257 (diff) | |
Fix TypeCheckingCache concurrency and candidate lifetime. (#6444)
* Fix TypeCheckingCache concurrency.
* Fix.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index ec90ee418..001354162 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -809,9 +809,12 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe RefPtr<Linkage> linkage = new Linkage(this, astBuilder, getBuiltinLinkage()); - if (m_typeCheckingCache) - linkage->m_typeCheckingCache = - new TypeCheckingCache(*static_cast<TypeCheckingCache*>(m_typeCheckingCache.get())); + { + std::lock_guard<std::mutex> lock(m_typeCheckingCacheMutex); + if (m_typeCheckingCache) + linkage->m_typeCheckingCache = + new TypeCheckingCache(*static_cast<TypeCheckingCache*>(m_typeCheckingCache.get())); + } linkage->setMatrixLayoutMode(desc.defaultMatrixLayoutMode); @@ -1308,14 +1311,16 @@ Linkage::~Linkage() if (m_typeCheckingCache) { auto globalSession = getSessionImpl(); + std::lock_guard<std::mutex> lock(globalSession->m_typeCheckingCacheMutex); if (!globalSession->m_typeCheckingCache || globalSession->getTypeCheckingCache()->resolvedOperatorOverloadCache.getCount() < getTypeCheckingCache()->resolvedOperatorOverloadCache.getCount()) { globalSession->m_typeCheckingCache = m_typeCheckingCache; + getTypeCheckingCache()->version++; } + destroyTypeCheckingCache(); } - destroyTypeCheckingCache(); } SearchDirectoryList& Linkage::getSearchDirectories() |
