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
#include "llvm/IR/ValueMap.h"
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/IR/ValueMap.h"
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Mutex.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include <map>
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include <map>
#include <string>
#include <vector>
#include <string>
#include <vector>
class JITMemoryManager;
class MachineCodeInfo;
class Module;
class JITMemoryManager;
class MachineCodeInfo;
class Module;
class ObjectCache;
class RTDyldMemoryManager;
class Triple;
class ObjectCache;
class RTDyldMemoryManager;
class Triple;
public:
struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
typedef ExecutionEngineState *ExtraData;
public:
struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
typedef ExecutionEngineState *ExtraData;
- static sys::Mutex *getMutex(ExecutionEngineState *EES);
+ static std::recursive_mutex *getMutex(ExecutionEngineState *EES);
static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
static void onRAUW(ExecutionEngineState *, const GlobalValue *,
const GlobalValue *);
static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
static void onRAUW(ExecutionEngineState *, const GlobalValue *,
const GlobalValue *);
/// lock - This lock protects the ExecutionEngine, MCJIT, JIT, JITResolver and
/// JITEmitter classes. It must be held while changing the internal state of
/// any of those classes.
/// lock - This lock protects the ExecutionEngine, MCJIT, JIT, JITResolver and
/// JITEmitter classes. It must be held while changing the internal state of
/// any of those classes.
+ std::recursive_mutex lock;
//===--------------------------------------------------------------------===//
// ExecutionEngine Startup
//===--------------------------------------------------------------------===//
// ExecutionEngine Startup
#include "llvm/ADT/DenseMap.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/IR/ValueHandle.h"
-#include "llvm/Support/Mutex.h"
#include "llvm/Support/type_traits.h"
#include <iterator>
#include "llvm/Support/type_traits.h"
#include <iterator>
/// This class defines the default behavior for configurable aspects of
/// ValueMap<>. User Configs should inherit from this class to be as compatible
/// as possible with future versions of ValueMap.
/// This class defines the default behavior for configurable aspects of
/// ValueMap<>. User Configs should inherit from this class to be as compatible
/// as possible with future versions of ValueMap.
-template<typename KeyT, typename MutexT = sys::Mutex>
+template<typename KeyT, typename MutexT = std::recursive_mutex>
struct ValueMapConfig {
typedef MutexT mutex_type;
struct ValueMapConfig {
typedef MutexT mutex_type;
ValueMapCallbackVH Copy(*this);
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
ValueMapCallbackVH Copy(*this);
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
Copy.Map->Map.erase(Copy); // Definitely destroys *this.
if (M)
Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
Copy.Map->Map.erase(Copy); // Definitely destroys *this.
if (M)
}
void allUsesReplacedWith(Value *new_key) override {
assert(isa<KeySansPointerT>(new_key) &&
}
void allUsesReplacedWith(Value *new_key) override {
assert(isa<KeySansPointerT>(new_key) &&
ValueMapCallbackVH Copy(*this);
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
ValueMapCallbackVH Copy(*this);
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
if (M)
KeyT typed_new_key = cast<KeySansPointerT>(new_key);
// Can destroy *this:
KeyT typed_new_key = cast<KeySansPointerT>(new_key);
// Can destroy *this:
}
void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
}
void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
<< "\' to [" << Addr << "]\n";);
DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
<< "\' to [" << Addr << "]\n";);
}
void ExecutionEngine::clearAllGlobalMappings() {
}
void ExecutionEngine::clearAllGlobalMappings() {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
EEState.getGlobalAddressMap().clear();
EEState.getGlobalAddressReverseMap().clear();
}
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
EEState.getGlobalAddressMap().clear();
EEState.getGlobalAddressReverseMap().clear();
}
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
EEState.RemoveMapping(FI);
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
EEState.RemoveMapping(FI);
}
void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
}
void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
ExecutionEngineState::GlobalAddressMapTy &Map =
EEState.getGlobalAddressMap();
ExecutionEngineState::GlobalAddressMapTy &Map =
EEState.getGlobalAddressMap();
}
void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
}
void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
ExecutionEngineState::GlobalAddressMapTy::iterator I =
EEState.getGlobalAddressMap().find(GV);
ExecutionEngineState::GlobalAddressMapTy::iterator I =
EEState.getGlobalAddressMap().find(GV);
}
const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
}
const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
// If we haven't computed the reverse mapping yet, do so first.
if (EEState.getGlobalAddressReverseMap().empty()) {
// If we haven't computed the reverse mapping yet, do so first.
if (EEState.getGlobalAddressReverseMap().empty()) {
if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
return getPointerToFunction(F);
if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
return getPointerToFunction(F);
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
if (void *P = EEState.getGlobalAddressMap()[GV])
return P;
if (void *P = EEState.getGlobalAddressMap()[GV])
return P;
: EE(EE), GlobalAddressMap(this) {
}
: EE(EE), GlobalAddressMap(this) {
}
ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
return &EES->EE.lock;
}
ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
return &EES->EE.lock;
}
/// bugpoint or gdb users to search for a function by name without any context.
class JitPool {
SmallPtrSet<JIT*, 1> JITs; // Optimize for process containing just 1 JIT.
/// bugpoint or gdb users to search for a function by name without any context.
class JitPool {
SmallPtrSet<JIT*, 1> JITs; // Optimize for process containing just 1 JIT.
- mutable sys::Mutex Lock;
+ mutable std::recursive_mutex Lock;
public:
void Add(JIT *jit) {
public:
void Add(JIT *jit) {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
JITs.insert(jit);
}
void Remove(JIT *jit) {
JITs.insert(jit);
}
void Remove(JIT *jit) {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
JITs.erase(jit);
}
void *getPointerToNamedFunction(const char *Name) const {
JITs.erase(jit);
}
void *getPointerToNamedFunction(const char *Name) const {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
assert(JITs.size() != 0 && "No Jit registered");
//search function in every instance of JIT
for (SmallPtrSet<JIT*, 1>::const_iterator Jit = JITs.begin(),
assert(JITs.size() != 0 && "No Jit registered");
//search function in every instance of JIT
for (SmallPtrSet<JIT*, 1>::const_iterator Jit = JITs.begin(),
AllJits->Add(this);
// Add target data
AllJits->Add(this);
// Add target data
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
FunctionPassManager &PM = jitstate->getPM();
M->setDataLayout(TM.getDataLayout());
PM.add(new DataLayoutPass(M));
FunctionPassManager &PM = jitstate->getPM();
M->setDataLayout(TM.getDataLayout());
PM.add(new DataLayoutPass(M));
/// addModule - Add a new Module to the JIT. If we previously removed the last
/// Module, we need re-initialize jitstate with a valid Module.
void JIT::addModule(Module *M) {
/// addModule - Add a new Module to the JIT. If we previously removed the last
/// Module, we need re-initialize jitstate with a valid Module.
void JIT::addModule(Module *M) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
if (Modules.empty()) {
assert(!jitstate && "jitstate should be NULL if Modules vector is empty!");
if (Modules.empty()) {
assert(!jitstate && "jitstate should be NULL if Modules vector is empty!");
bool JIT::removeModule(Module *M) {
bool result = ExecutionEngine::removeModule(M);
bool JIT::removeModule(Module *M) {
bool result = ExecutionEngine::removeModule(M);
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
if (jitstate && jitstate->getModule() == M) {
delete jitstate;
if (jitstate && jitstate->getModule() == M) {
delete jitstate;
void JIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
void JIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
EventListeners.push_back(L);
}
void JIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
EventListeners.push_back(L);
}
void JIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
std::vector<JITEventListener*>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
std::vector<JITEventListener*>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
const Function &F,
void *Code, size_t Size,
const JITEvent_EmittedFunctionDetails &Details) {
const Function &F,
void *Code, size_t Size,
const JITEvent_EmittedFunctionDetails &Details) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFunctionEmitted(F, Code, Size, Details);
}
}
void JIT::NotifyFreeingMachineCode(void *OldPtr) {
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFunctionEmitted(F, Code, Size, Details);
}
}
void JIT::NotifyFreeingMachineCode(void *OldPtr) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingMachineCode(OldPtr);
}
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingMachineCode(OldPtr);
}
/// GlobalAddress[F] with the address of F's machine code.
///
void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
/// GlobalAddress[F] with the address of F's machine code.
///
void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
class MCIListener : public JITEventListener {
MachineCodeInfo *const MCI;
class MCIListener : public JITEventListener {
MachineCodeInfo *const MCI;
if (void *Addr = getPointerToGlobalIfAvailable(F))
return Addr; // Check if function already code gen'd
if (void *Addr = getPointerToGlobalIfAvailable(F))
return Addr; // Check if function already code gen'd
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
// Now that this thread owns the lock, make sure we read in the function if it
// exists in this Module.
// Now that this thread owns the lock, make sure we read in the function if it
// exists in this Module.
}
void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) {
}
void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
}
void JIT::clearPointerToBasicBlock(const BasicBlock *BB) {
}
void JIT::clearPointerToBasicBlock(const BasicBlock *BB) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
getBasicBlockAddressMap().erase(BB);
}
getBasicBlockAddressMap().erase(BB);
}
(void)getPointerToFunction(BB->getParent());
// resolve basic block address
(void)getPointerToFunction(BB->getParent());
// resolve basic block address
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
/// variable, possibly emitting it to memory if needed. This is used by the
/// Emitter.
void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
/// variable, possibly emitting it to memory if needed. This is used by the
/// Emitter.
void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
void *Ptr = getPointerToGlobalIfAvailable(GV);
if (Ptr) return Ptr;
void *Ptr = getPointerToGlobalIfAvailable(GV);
if (Ptr) return Ptr;
size_t S = getDataLayout()->getTypeAllocSize(GlobalType);
size_t A = getDataLayout()->getPreferredAlignment(GV);
if (GV->isThreadLocal()) {
size_t S = getDataLayout()->getTypeAllocSize(GlobalType);
size_t A = getDataLayout()->getPreferredAlignment(GV);
if (GV->isThreadLocal()) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
Ptr = TJI.allocateThreadLocalMemory(S);
} else if (TJI.allocateSeparateGVMemory()) {
if (A <= 8) {
Ptr = TJI.allocateThreadLocalMemory(S);
} else if (TJI.allocateSeparateGVMemory()) {
if (A <= 8) {
}
void JIT::addPendingFunction(Function *F) {
}
void JIT::addPendingFunction(Function *F) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
jitstate->getPendingFunctions().push_back(F);
}
jitstate->getPendingFunctions().push_back(F);
}
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
-#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetJITInfo.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetJITInfo.h"
#ifndef NDEBUG
#include <iomanip>
#endif
#ifndef NDEBUG
#include <iomanip>
#endif
using namespace llvm;
#define DEBUG_TYPE "jit"
using namespace llvm;
#define DEBUG_TYPE "jit"
std::map<void*, JITResolver*> Map;
/// Guards Map from concurrent accesses.
std::map<void*, JITResolver*> Map;
/// Guards Map from concurrent accesses.
- mutable sys::Mutex Lock;
+ mutable std::recursive_mutex Lock;
public:
/// Registers a Stub to be resolved by Resolver.
void RegisterStubResolver(void *Stub, JITResolver *Resolver) {
public:
/// Registers a Stub to be resolved by Resolver.
void RegisterStubResolver(void *Stub, JITResolver *Resolver) {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
Map.insert(std::make_pair(Stub, Resolver));
}
/// Unregisters the Stub when it's invalidated.
void UnregisterStubResolver(void *Stub) {
Map.insert(std::make_pair(Stub, Resolver));
}
/// Unregisters the Stub when it's invalidated.
void UnregisterStubResolver(void *Stub) {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
Map.erase(Stub);
}
/// Returns the JITResolver instance that owns the Stub.
JITResolver *getResolverFromStub(void *Stub) const {
Map.erase(Stub);
}
/// Returns the JITResolver instance that owns the Stub.
JITResolver *getResolverFromStub(void *Stub) const {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
// This is the same trick as in LookupFunctionFromCallSite from
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
// This is the same trick as in LookupFunctionFromCallSite from
/// True if any stubs refer to the given resolver. Only used in an assert().
/// O(N)
bool ResolverHasStubs(JITResolver* Resolver) const {
/// True if any stubs refer to the given resolver. Only used in an assert().
/// O(N)
bool ResolverHasStubs(JITResolver* Resolver) const {
- MutexGuard guard(Lock);
+ std::lock_guard<std::recursive_mutex> guard(Lock);
for (std::map<void*, JITResolver*>::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) {
if (I->second == Resolver)
for (std::map<void*, JITResolver*>::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) {
if (I->second == Resolver)
/// getLazyFunctionStubIfAvailable - This returns a pointer to a function stub
/// if it has already been created.
void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
/// getLazyFunctionStubIfAvailable - This returns a pointer to a function stub
/// if it has already been created.
void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
- MutexGuard locked(TheJIT->lock);
+ std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
// If we already have a stub for this function, recycle it.
return state.getFunctionToLazyStubMap().lookup(F);
// If we already have a stub for this function, recycle it.
return state.getFunctionToLazyStubMap().lookup(F);
/// getFunctionStub - This returns a pointer to a function stub, creating
/// one on demand as needed.
void *JITResolver::getLazyFunctionStub(Function *F) {
/// getFunctionStub - This returns a pointer to a function stub, creating
/// one on demand as needed.
void *JITResolver::getLazyFunctionStub(Function *F) {
- MutexGuard locked(TheJIT->lock);
+ std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
// If we already have a lazy stub for this function, recycle it.
void *&Stub = state.getFunctionToLazyStubMap()[F];
// If we already have a lazy stub for this function, recycle it.
void *&Stub = state.getFunctionToLazyStubMap()[F];
/// getGlobalValueIndirectSym - Return a lazy pointer containing the specified
/// GV address.
void *JITResolver::getGlobalValueIndirectSym(GlobalValue *GV, void *GVAddress) {
/// getGlobalValueIndirectSym - Return a lazy pointer containing the specified
/// GV address.
void *JITResolver::getGlobalValueIndirectSym(GlobalValue *GV, void *GVAddress) {
- MutexGuard locked(TheJIT->lock);
+ std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
// If we already have a stub for this global variable, recycle it.
void *&IndirectSym = state.getGlobalToIndirectSymMap()[GV];
// If we already have a stub for this global variable, recycle it.
void *&IndirectSym = state.getGlobalToIndirectSymMap()[GV];
// Only lock for getting the Function. The call getPointerToFunction made
// in this function might trigger function materializing, which requires
// JIT lock to be unlocked.
// Only lock for getting the Function. The call getPointerToFunction made
// in this function might trigger function materializing, which requires
// JIT lock to be unlocked.
- MutexGuard locked(JR->TheJIT->lock);
+ std::lock_guard<std::recursive_mutex> guard(JR->TheJIT->lock);
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
}
// Reacquire the lock to update the GOT map.
}
// Reacquire the lock to update the GOT map.
- MutexGuard locked(JR->TheJIT->lock);
+ std::lock_guard<std::recursive_mutex> locked(JR->TheJIT->lock);
// We might like to remove the call site from the CallSiteToFunction map, but
// we can't do that! Multiple threads could be stuck, waiting to acquire the
// We might like to remove the call site from the CallSiteToFunction map, but
// we can't do that! Multiple threads could be stuck, waiting to acquire the
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#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;
#include "llvm/Target/TargetLowering.h"
using namespace llvm;
- 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
// 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
}
void MCJIT::addModule(Module *M) {
}
void MCJIT::addModule(Module *M) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
OwnedModules.addModule(M);
}
bool MCJIT::removeModule(Module *M) {
OwnedModules.addModule(M);
}
bool MCJIT::removeModule(Module *M) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
return OwnedModules.removeModule(M);
}
return OwnedModules.removeModule(M);
}
void MCJIT::setObjectCache(ObjectCache* NewCache) {
void MCJIT::setObjectCache(ObjectCache* NewCache) {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
ObjCache = NewCache;
}
ObjectBufferStream* MCJIT::emitObject(Module *M) {
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,
// 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,
void MCJIT::generateCodeForModule(Module *M) {
// Get a thread lock to make sure we aren't trying to load multiple times
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) &&
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) &&
}
void MCJIT::finalizeLoadedModules() {
}
void MCJIT::finalizeLoadedModules() {
- MutexGuard locked(lock);
+ std::lock_guard<std::recursive_mutex> locked(lock);
// Resolve any outstanding relocations.
Dyld.resolveRelocations();
// Resolve any outstanding relocations.
Dyld.resolveRelocations();
// FIXME: Rename this.
void MCJIT::finalizeObject() {
// 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();
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
E = OwnedModules.end_added();
}
void MCJIT::finalizeModule(Module *M) {
}
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.");
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
Module *MCJIT::findModuleForSymbol(const std::string &Name,
bool CheckFunctionsOnly) {
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(),
// If it hasn't already been generated, see if it's in one of our modules.
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
uint64_t MCJIT::getSymbolAddress(const std::string &Name,
bool CheckFunctionsOnly)
{
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);
// First, check to see if we already have this symbol.
uint64_t Addr = getExistingSymbolAddress(Name);
}
uint64_t MCJIT::getGlobalValueAddress(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();
uint64_t Result = getSymbolAddress(Name, false);
if (Result != 0)
finalizeLoadedModules();
}
uint64_t MCJIT::getFunctionAddress(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();
uint64_t Result = getSymbolAddress(Name, true);
if (Result != 0)
finalizeLoadedModules();
// Deprecated. Use getFunctionAddress instead.
void *MCJIT::getPointerToFunction(Function *F) {
// 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();
if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
bool AbortOnFailure = !F->hasExternalWeakLinkage();
void MCJIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
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;
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()) {
SmallVector<JITEventListener*, 2>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
}
}
void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
}
}
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) {
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);
}
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingObject(Obj);
}
};
static void onRAUW(const ExtraData &Data, KeyT Old, KeyT New) {
*Data.CalledRAUW = true;
};
static void onRAUW(const ExtraData &Data, KeyT Old, KeyT New) {
*Data.CalledRAUW = true;
- EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
+ EXPECT_FALSE(Data.M->try_lock()) << "Mutex should already be locked.";
}
static void onDelete(const ExtraData &Data, KeyT Old) {
*Data.CalledDeleted = true;
}
static void onDelete(const ExtraData &Data, KeyT Old) {
*Data.CalledDeleted = true;
- EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
+ EXPECT_FALSE(Data.M->try_lock()) << "Mutex should already be locked.";
}
static MutexT *getMutex(const ExtraData &Data) { return Data.M; }
};
#if LLVM_ENABLE_THREADS
TYPED_TEST(ValueMapTest, LocksMutex) {
}
static MutexT *getMutex(const ExtraData &Data) { return Data.M; }
};
#if LLVM_ENABLE_THREADS
TYPED_TEST(ValueMapTest, LocksMutex) {
- sys::Mutex M(false); // Not recursive.
+ std::mutex M; // Not recursive.
bool CalledRAUW = false, CalledDeleted = false;
bool CalledRAUW = false, CalledDeleted = false;
- typedef LockMutex<TypeParam*, sys::Mutex> ConfigType;
+ typedef LockMutex<TypeParam*, std::mutex> ConfigType;
typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted};
ValueMap<TypeParam*, int, ConfigType> VM(Data);
VM[this->BitcastV.get()] = 7;
typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted};
ValueMap<TypeParam*, int, ConfigType> VM(Data);
VM[this->BitcastV.get()] = 7;