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>
|
||||
GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
|
||||
auto &G = *DefGenerator;
|
||||
std::lock_guard<std::mutex> Lock(GeneratorsMutex);
|
||||
DefGenerators.push_back(std::move(DefGenerator));
|
||||
ES.runSessionLocked([&] {
|
||||
DefGenerators.push_back(std::move(DefGenerator));
|
||||
});
|
||||
return G;
|
||||
}
|
||||
|
||||
|
|
|
@ -642,13 +642,14 @@ ResourceTrackerSP JITDylib::createResourceTracker() {
|
|||
}
|
||||
|
||||
void JITDylib::removeGenerator(DefinitionGenerator &G) {
|
||||
std::lock_guard<std::mutex> Lock(GeneratorsMutex);
|
||||
auto I = llvm::find_if(DefGenerators,
|
||||
[&](const std::shared_ptr<DefinitionGenerator> &H) {
|
||||
return H.get() == &G;
|
||||
});
|
||||
assert(I != DefGenerators.end() && "Generator not found");
|
||||
DefGenerators.erase(I);
|
||||
ES.runSessionLocked([&] {
|
||||
auto I = llvm::find_if(DefGenerators,
|
||||
[&](const std::shared_ptr<DefinitionGenerator> &H) {
|
||||
return H.get() == &G;
|
||||
});
|
||||
assert(I != DefGenerators.end() && "Generator not found");
|
||||
DefGenerators.erase(I);
|
||||
});
|
||||
}
|
||||
|
||||
Expected<SymbolFlagsMap>
|
||||
|
@ -2311,8 +2312,11 @@ void ExecutionSession::OL_applyQueryPhase1(
|
|||
});
|
||||
|
||||
// Build the definition generator stack for this JITDylib.
|
||||
for (auto &DG : reverse(JD.DefGenerators))
|
||||
IPLS->CurDefGeneratorStack.push_back(DG);
|
||||
runSessionLocked([&] {
|
||||
IPLS->CurDefGeneratorStack.reserve(JD.DefGenerators.size());
|
||||
for (auto &DG : reverse(JD.DefGenerators))
|
||||
IPLS->CurDefGeneratorStack.push_back(DG);
|
||||
});
|
||||
|
||||
// Flag that we've done our initialization.
|
||||
IPLS->NewJITDylib = false;
|
||||
|
|
Loading…
Reference in New Issue