From ee448630bdf7eb6037fe2c50518d32010c433ca3 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 12 Jul 2005 15:51:55 +0000 Subject: For PR540: This patch completes the changes for making lli thread-safe. Here's the list of changes: * The Support/ThreadSupport* files were removed and replaced with the MutexGuard.h file since all ThreadSupport* declared was a Mutex Guard. The implementation of MutexGuard.h is now based on sys::Mutex which hides its implementation and makes it unnecessary to have the -NoSupport.h and -PThreads.h versions of ThreadSupport. * All places in ExecutionEngine that previously referred to "Mutex" now refer to sys::Mutex * All places in ExecutionEngine that previously referred to "MutexLocker" now refer to MutexGuard (this is frivolous but I believe the technically correct name for such a class is "Guard" not a "Locker"). These changes passed all of llvm-test. All we need now are some test cases that actually use multiple threads. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22404 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/ExecutionEngine.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/ExecutionEngine/ExecutionEngine.cpp') diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index f72ddcbba6..36f7d2fdfc 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -50,16 +50,18 @@ ExecutionEngine::~ExecutionEngine() { /// at the specified address. /// const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { + MutexGuard locked(lock); + // If we haven't computed the reverse mapping yet, do so first. - if (GlobalAddressReverseMap.empty()) { + if (state.getGlobalAddressReverseMap(locked).empty()) { for (std::map::iterator I = - GlobalAddressMap.begin(), E = GlobalAddressMap.end(); I != E; ++I) - GlobalAddressReverseMap.insert(std::make_pair(I->second, I->first)); + state.getGlobalAddressMap(locked).begin(), E = state.getGlobalAddressMap(locked).end(); I != E; ++I) + state.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second, I->first)); } std::map::iterator I = - GlobalAddressReverseMap.find(Addr); - return I != GlobalAddressReverseMap.end() ? I->second : 0; + state.getGlobalAddressReverseMap(locked).find(Addr); + return I != state.getGlobalAddressReverseMap(locked).end() ? I->second : 0; } // CreateArgv - Turn a vector of strings into a nice argv style array of @@ -168,8 +170,9 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { if (Function *F = const_cast(dyn_cast(GV))) return getPointerToFunction(F); - assert(GlobalAddressMap[GV] && "Global hasn't had an address allocated yet?"); - return GlobalAddressMap[GV]; + MutexGuard locked(lock); + assert(state.getGlobalAddressMap(locked)[GV] && "Global hasn't had an address allocated yet?"); + return state.getGlobalAddressMap(locked)[GV]; } /// FIXME: document -- cgit v1.2.3-18-g5258