forked from OSchip/llvm-project
[ORC] Only use JITDylib::GeneratorsMutex while running generators.
GeneratorsMutex should prevent lookups from proceeding through the generators of a single JITDylib concurrently (since this could result in redundant attempts to generate definitions). Mutation of the generators list itself should be done under the session lock.
This commit is contained in:
parent
9355d11597
commit
9eb591f0ac
|
@ -1680,8 +1680,9 @@ Error MaterializationResponsibility::withResourceKeyDo(Func &&F) const {
|
||||||
template <typename GeneratorT>
|
template <typename GeneratorT>
|
||||||
GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
|
GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
|
||||||
auto &G = *DefGenerator;
|
auto &G = *DefGenerator;
|
||||||
std::lock_guard<std::mutex> Lock(GeneratorsMutex);
|
ES.runSessionLocked([&] {
|
||||||
DefGenerators.push_back(std::move(DefGenerator));
|
DefGenerators.push_back(std::move(DefGenerator));
|
||||||
|
});
|
||||||
return G;
|
return G;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -642,13 +642,14 @@ ResourceTrackerSP JITDylib::createResourceTracker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JITDylib::removeGenerator(DefinitionGenerator &G) {
|
void JITDylib::removeGenerator(DefinitionGenerator &G) {
|
||||||
std::lock_guard<std::mutex> Lock(GeneratorsMutex);
|
ES.runSessionLocked([&] {
|
||||||
auto I = llvm::find_if(DefGenerators,
|
auto I = llvm::find_if(DefGenerators,
|
||||||
[&](const std::shared_ptr<DefinitionGenerator> &H) {
|
[&](const std::shared_ptr<DefinitionGenerator> &H) {
|
||||||
return H.get() == &G;
|
return H.get() == &G;
|
||||||
});
|
});
|
||||||
assert(I != DefGenerators.end() && "Generator not found");
|
assert(I != DefGenerators.end() && "Generator not found");
|
||||||
DefGenerators.erase(I);
|
DefGenerators.erase(I);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<SymbolFlagsMap>
|
Expected<SymbolFlagsMap>
|
||||||
|
@ -2311,8 +2312,11 @@ void ExecutionSession::OL_applyQueryPhase1(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Build the definition generator stack for this JITDylib.
|
// Build the definition generator stack for this JITDylib.
|
||||||
for (auto &DG : reverse(JD.DefGenerators))
|
runSessionLocked([&] {
|
||||||
IPLS->CurDefGeneratorStack.push_back(DG);
|
IPLS->CurDefGeneratorStack.reserve(JD.DefGenerators.size());
|
||||||
|
for (auto &DG : reverse(JD.DefGenerators))
|
||||||
|
IPLS->CurDefGeneratorStack.push_back(DG);
|
||||||
|
});
|
||||||
|
|
||||||
// Flag that we've done our initialization.
|
// Flag that we've done our initialization.
|
||||||
IPLS->NewJITDylib = false;
|
IPLS->NewJITDylib = false;
|
||||||
|
|
Loading…
Reference in New Issue