[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.
This commit is contained in:
Artem Chikin
2024-02-05 13:46:41 -08:00
parent a48dc87f86
commit 0046165dad
2 changed files with 3 additions and 1 deletions

View File

@@ -215,10 +215,12 @@ bool DependencyScanningTool::loadCache(llvm::StringRef path) {
}
void DependencyScanningTool::resetCache() {
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
ScanningService.reset(new SwiftDependencyScanningService());
}
void DependencyScanningTool::resetDiagnostics() {
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
CDC.reset();
}