Skip to content

Commit 0046165

Browse files
committed
[DependencyScanning] Isolate 'DependencyScanningTool' reset operations
Guard 'resetCache' and 'resetDiagnostics' as critical sections using 'DependencyScanningToolStateLock'. Otherwise there's a chance that one thread in the scanner is doing a reset on the diagnostic consumer, while some other thread is adding this diagnostic consumer to another scan instance which may also be populating said consumer at the time. Similarly, for resetting 'ScanningService' though it is much more unlikely to be reset while in-use by other scanning actions.
1 parent a48dc87 commit 0046165

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ SwiftDependencyScanningService::getDependenciesMap(
592592
}
593593

594594
void SwiftDependencyScanningService::configureForContextHash(StringRef scanningContextHash) {
595+
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
595596
auto knownContext = ContextSpecificCacheMap.find(scanningContextHash);
596597
if (knownContext == ContextSpecificCacheMap.end()) {
597598
// First time scanning with this context, initialize context-specific state.
@@ -601,7 +602,6 @@ void SwiftDependencyScanningService::configureForContextHash(StringRef scanningC
601602
kind != ModuleDependencyKind::LastKind; ++kind) {
602603
contextSpecificCache->ModuleDependenciesMap.insert({kind, ModuleNameToDependencyMap()});
603604
}
604-
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
605605
ContextSpecificCacheMap.insert({scanningContextHash.str(), std::move(contextSpecificCache)});
606606
AllContextHashes.push_back(scanningContextHash.str());
607607
}

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ bool DependencyScanningTool::loadCache(llvm::StringRef path) {
215215
}
216216

217217
void DependencyScanningTool::resetCache() {
218+
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
218219
ScanningService.reset(new SwiftDependencyScanningService());
219220
}
220221

221222
void DependencyScanningTool::resetDiagnostics() {
223+
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
222224
CDC.reset();
223225
}
224226

0 commit comments

Comments
 (0)