[ORC] Make LocalIndirectStubsManager's operations thread-safe.
Locks stub management operations and switches to atomic update for stub pointers. llvm-svn: 343262
This commit is contained in:
parent
cf0949aa9f
commit
01bb2baaa1
|
|
@ -295,6 +295,7 @@ class LocalIndirectStubsManager : public IndirectStubsManager {
|
|||
public:
|
||||
Error createStub(StringRef StubName, JITTargetAddress StubAddr,
|
||||
JITSymbolFlags StubFlags) override {
|
||||
std::lock_guard<std::mutex> Lock(StubsMutex);
|
||||
if (auto Err = reserveStubs(1))
|
||||
return Err;
|
||||
|
||||
|
|
@ -304,6 +305,7 @@ public:
|
|||
}
|
||||
|
||||
Error createStubs(const StubInitsMap &StubInits) override {
|
||||
std::lock_guard<std::mutex> Lock(StubsMutex);
|
||||
if (auto Err = reserveStubs(StubInits.size()))
|
||||
return Err;
|
||||
|
||||
|
|
@ -315,6 +317,7 @@ public:
|
|||
}
|
||||
|
||||
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
|
||||
std::lock_guard<std::mutex> Lock(StubsMutex);
|
||||
auto I = StubIndexes.find(Name);
|
||||
if (I == StubIndexes.end())
|
||||
return nullptr;
|
||||
|
|
@ -330,6 +333,7 @@ public:
|
|||
}
|
||||
|
||||
JITEvaluatedSymbol findPointer(StringRef Name) override {
|
||||
std::lock_guard<std::mutex> Lock(StubsMutex);
|
||||
auto I = StubIndexes.find(Name);
|
||||
if (I == StubIndexes.end())
|
||||
return nullptr;
|
||||
|
|
@ -342,11 +346,15 @@ public:
|
|||
}
|
||||
|
||||
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {
|
||||
using AtomicIntPtr = std::atomic<uintptr_t>;
|
||||
|
||||
std::lock_guard<std::mutex> Lock(StubsMutex);
|
||||
auto I = StubIndexes.find(Name);
|
||||
assert(I != StubIndexes.end() && "No stub pointer for symbol");
|
||||
auto Key = I->second.first;
|
||||
*IndirectStubsInfos[Key.first].getPtr(Key.second) =
|
||||
reinterpret_cast<void *>(static_cast<uintptr_t>(NewAddr));
|
||||
AtomicIntPtr *AtomicStubPtr = reinterpret_cast<AtomicIntPtr *>(
|
||||
IndirectStubsInfos[Key.first].getPtr(Key.second));
|
||||
*AtomicStubPtr = static_cast<uintptr_t>(NewAddr);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
|
|
@ -376,6 +384,7 @@ private:
|
|||
StubIndexes[StubName] = std::make_pair(Key, StubFlags);
|
||||
}
|
||||
|
||||
std::mutex StubsMutex;
|
||||
std::vector<typename TargetT::IndirectStubsInfo> IndirectStubsInfos;
|
||||
using StubKey = std::pair<uint16_t, uint16_t>;
|
||||
std::vector<StubKey> FreeStubs;
|
||||
|
|
|
|||
Loading…
Reference in New Issue