From 9e465c776af22ff7a19818b1b135b9e5287aa603 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 24 Feb 2025 12:51:51 -0800 Subject: Fix TypeCheckingCache concurrency and candidate lifetime. (#6444) * Fix TypeCheckingCache concurrency. * Fix. --- source/slang/slang.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source/slang/slang.cpp') 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 = new Linkage(this, astBuilder, getBuiltinLinkage()); - if (m_typeCheckingCache) - linkage->m_typeCheckingCache = - new TypeCheckingCache(*static_cast(m_typeCheckingCache.get())); + { + std::lock_guard lock(m_typeCheckingCacheMutex); + if (m_typeCheckingCache) + linkage->m_typeCheckingCache = + new TypeCheckingCache(*static_cast(m_typeCheckingCache.get())); + } linkage->setMatrixLayoutMode(desc.defaultMatrixLayoutMode); @@ -1308,14 +1311,16 @@ Linkage::~Linkage() if (m_typeCheckingCache) { auto globalSession = getSessionImpl(); + std::lock_guard 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() -- cgit v1.2.3