@@ -742,13 +742,13 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
742
742
// results back to the shared set for future lookups.
743
743
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> seenClangModules =
744
744
cache.getAlreadySeenClangModules ();
745
- std::mutex cacheAccessLock ;
745
+ std::mutex lookupResultLock ;
746
746
auto scanForClangModuleDependency =
747
747
[this , &cache, &moduleLookupResult,
748
- &cacheAccessLock , &seenClangModules](Identifier moduleIdentifier) {
748
+ &lookupResultLock , &seenClangModules](Identifier moduleIdentifier) {
749
749
auto moduleName = moduleIdentifier.str ();
750
750
{
751
- std::lock_guard<std::mutex> guard (cacheAccessLock );
751
+ std::lock_guard<std::mutex> guard (lookupResultLock );
752
752
if (cache.hasDependency (moduleName, ModuleDependencyKind::Clang))
753
753
return ;
754
754
}
@@ -766,7 +766,7 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
766
766
// if looking for a module that was discovered as a transitive dependency
767
767
// in this scan.
768
768
{
769
- std::lock_guard<std::mutex> guard (cacheAccessLock );
769
+ std::lock_guard<std::mutex> guard (lookupResultLock );
770
770
moduleLookupResult.insert_or_assign (moduleName, moduleDependencies);
771
771
if (!moduleDependencies.empty ())
772
772
cache.recordDependencies (moduleDependencies);
@@ -926,16 +926,19 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
926
926
for (const auto &dependsOn : moduleDependencyInfo.getModuleImports ())
927
927
moduleLookupResult.insert (
928
928
std::make_pair (dependsOn.importIdentifier , std::nullopt));
929
+ std::mutex lookupResultLock;
929
930
930
931
// A scanning task to query a module by-name. If the module already exists
931
932
// in the cache, do nothing and return.
932
933
auto scanForSwiftModuleDependency =
933
- [this , &cache, &moduleLookupResult](Identifier moduleIdentifier,
934
- bool isTestable) {
934
+ [this , &cache, &lookupResultLock, & moduleLookupResult](Identifier moduleIdentifier,
935
+ bool isTestable) {
935
936
auto moduleName = moduleIdentifier.str ().str ();
936
- // If this is already in the cache, no work to do here
937
- if (cache.hasSwiftDependency (moduleName))
938
- return ;
937
+ {
938
+ std::lock_guard<std::mutex> guard (lookupResultLock);
939
+ if (cache.hasSwiftDependency (moduleName))
940
+ return ;
941
+ }
939
942
940
943
auto moduleDependencies = withDependencyScanningWorker (
941
944
[&cache, moduleIdentifier,
@@ -944,7 +947,11 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
944
947
moduleIdentifier, cache.getModuleOutputPath (),
945
948
cache.getScanService ().getPrefixMapper (), isTestable);
946
949
});
947
- moduleLookupResult.insert_or_assign (moduleName, moduleDependencies);
950
+
951
+ {
952
+ std::lock_guard<std::mutex> guard (lookupResultLock);
953
+ moduleLookupResult.insert_or_assign (moduleName, moduleDependencies);
954
+ }
948
955
};
949
956
950
957
// Enque asynchronous lookup tasks
0 commit comments