Replace Execution Engine's mutex with std::recursive_mutex.

This change has a bit of a trickle down effect due to the fact that
there are a number of derived implementations of ExecutionEngine,
and that the mutex is not tightly encapsulated so is used by other
classes directly.

Reviewed by: rnk

Differential Revision: http://reviews.llvm.org/D4196

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211214 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zachary Turner
2014-06-18 20:17:35 +00:00
parent b2791542c2
commit 1f502bd9d7
7 changed files with 69 additions and 71 deletions

View File

@ -26,7 +26,6 @@
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MutexGuard.h"
#include "llvm/Target/TargetLowering.h"
using namespace llvm;
@ -66,7 +65,7 @@ MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM,
}
MCJIT::~MCJIT() {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// FIXME: We are managing our modules, so we do not want the base class
// ExecutionEngine to manage them as well. To avoid double destruction
// of the first (and only) module added in ExecutionEngine constructor
@ -102,12 +101,12 @@ MCJIT::~MCJIT() {
}
void MCJIT::addModule(Module *M) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
OwnedModules.addModule(M);
}
bool MCJIT::removeModule(Module *M) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
return OwnedModules.removeModule(M);
}
@ -129,12 +128,12 @@ void MCJIT::addArchive(object::Archive *A) {
void MCJIT::setObjectCache(ObjectCache* NewCache) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
ObjCache = NewCache;
}
ObjectBufferStream* MCJIT::emitObject(Module *M) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// This must be a module which has already been added but not loaded to this
// MCJIT instance, since these conditions are tested by our caller,
@ -174,7 +173,7 @@ ObjectBufferStream* MCJIT::emitObject(Module *M) {
void MCJIT::generateCodeForModule(Module *M) {
// Get a thread lock to make sure we aren't trying to load multiple times
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) &&
@ -214,7 +213,7 @@ void MCJIT::generateCodeForModule(Module *M) {
}
void MCJIT::finalizeLoadedModules() {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// Resolve any outstanding relocations.
Dyld.resolveRelocations();
@ -230,7 +229,7 @@ void MCJIT::finalizeLoadedModules() {
// FIXME: Rename this.
void MCJIT::finalizeObject() {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
E = OwnedModules.end_added();
@ -243,7 +242,7 @@ void MCJIT::finalizeObject() {
}
void MCJIT::finalizeModule(Module *M) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
@ -268,7 +267,7 @@ uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
Module *MCJIT::findModuleForSymbol(const std::string &Name,
bool CheckFunctionsOnly) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// If it hasn't already been generated, see if it's in one of our modules.
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
@ -292,7 +291,7 @@ Module *MCJIT::findModuleForSymbol(const std::string &Name,
uint64_t MCJIT::getSymbolAddress(const std::string &Name,
bool CheckFunctionsOnly)
{
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
// First, check to see if we already have this symbol.
uint64_t Addr = getExistingSymbolAddress(Name);
@ -336,7 +335,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name,
}
uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
uint64_t Result = getSymbolAddress(Name, false);
if (Result != 0)
finalizeLoadedModules();
@ -344,7 +343,7 @@ uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
}
uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
uint64_t Result = getSymbolAddress(Name, true);
if (Result != 0)
finalizeLoadedModules();
@ -353,7 +352,7 @@ uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
// Deprecated. Use getFunctionAddress instead.
void *MCJIT::getPointerToFunction(Function *F) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
bool AbortOnFailure = !F->hasExternalWeakLinkage();
@ -552,13 +551,13 @@ void *MCJIT::getPointerToNamedFunction(const std::string &Name,
void MCJIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
EventListeners.push_back(L);
}
void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
SmallVector<JITEventListener*, 2>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
@ -567,14 +566,14 @@ void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
}
}
void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
MemMgr.notifyObjectLoaded(this, &Obj);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyObjectEmitted(Obj);
}
}
void MCJIT::NotifyFreeingObject(const ObjectImage& Obj) {
MutexGuard locked(lock);
std::lock_guard<std::recursive_mutex> locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingObject(Obj);
}