@@ -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