Skip to content

Commit

Permalink
Merge pull request #75598 from cachemeifyoucan/eng/PR-127205953
Browse files Browse the repository at this point in the history
[DependencyScanner] Use mutex to protect all accesses to contextCacheMap
  • Loading branch information
cachemeifyoucan authored Jul 31, 2024
2 parents ceeb6ec + 9967e58 commit 541ee12
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ class SwiftDependencyScanningService {
std::vector<std::string> AllContextHashes;

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

/// Retrieve the dependencies map that corresponds to the given dependency
/// kind.
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(

SwiftDependencyScanningService::ContextSpecificGlobalCacheState *
SwiftDependencyScanningService::getCacheForScanningContextHash(StringRef scanningContextHash) const {
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
auto contextSpecificCache = ContextSpecificCacheMap.find(scanningContextHash);
assert(contextSpecificCache != ContextSpecificCacheMap.end() &&
"Global Module Dependencies Cache not configured with context-specific "
Expand All @@ -756,7 +757,6 @@ SwiftDependencyScanningService::getDependenciesMap(
ModuleNameToDependencyMap &
SwiftDependencyScanningService::getDependenciesMap(
ModuleDependencyKind kind, StringRef scanContextHash) {
llvm::sys::SmartScopedLock<true> Lock(ScanningServiceGlobalLock);
auto contextSpecificCache = getCacheForScanningContextHash(scanContextHash);
auto it = contextSpecificCache->ModuleDependenciesMap.find(kind);
assert(it != contextSpecificCache->ModuleDependenciesMap.end() &&
Expand Down

0 comments on commit 541ee12

Please sign in to comment.