Skip to content

Commit 9967e58

Browse files
[DependencyScanner] Use mutex to protect all accesses to contextCacheMap
Rather than only protecting the insertion and non-const access to `ContextSpecificCacheMap` in ScanningService, extend the mutex protection to all accesses. Even a 'const' lookup in the cache map is not thread safe because the `StringMap` could be in the process of being rehashed. rdar://127205953
1 parent f89db53 commit 9967e58

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ class SwiftDependencyScanningService {
998998
std::vector<std::string> AllContextHashes;
999999

10001000
/// Shared state mutual-exclusivity lock
1001-
llvm::sys::SmartMutex<true> ScanningServiceGlobalLock;
1001+
mutable llvm::sys::SmartMutex<true> ScanningServiceGlobalLock;
10021002

10031003
/// Retrieve the dependencies map that corresponds to the given dependency
10041004
/// kind.

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
736736

737737
SwiftDependencyScanningService::ContextSpecificGlobalCacheState *
738738
SwiftDependencyScanningService::getCacheForScanningContextHash(StringRef scanningContextHash) const {
739+
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
739740
auto contextSpecificCache = ContextSpecificCacheMap.find(scanningContextHash);
740741
assert(contextSpecificCache != ContextSpecificCacheMap.end() &&
741742
"Global Module Dependencies Cache not configured with context-specific "
@@ -756,7 +757,6 @@ SwiftDependencyScanningService::getDependenciesMap(
756757
ModuleNameToDependencyMap &
757758
SwiftDependencyScanningService::getDependenciesMap(
758759
ModuleDependencyKind kind, StringRef scanContextHash) {
759-
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
760760
auto contextSpecificCache = getCacheForScanningContextHash(scanContextHash);
761761
auto it = contextSpecificCache->ModuleDependenciesMap.find(kind);
762762
assert(it != contextSpecificCache->ModuleDependenciesMap.end() &&

0 commit comments

Comments
 (0)