Revert r190921. It broke Windows.

I'll roll it back in when I have a chance to look at it in detail.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190923 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Filip Pizlo 2013-09-18 06:37:55 +00:00
parent e77ea6b07e
commit 163df38bdf

View File

@ -14,7 +14,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Config/config.h"
@ -23,12 +22,31 @@
#include <cstring>
// Collection of symbol name/value pairs to be searched prior to any libraries.
static llvm::ManagedStatic<llvm::StringMap<void *> > ExplicitSymbols;
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > SymbolsMutex;
static llvm::StringMap<void *> *ExplicitSymbols = 0;
namespace {
struct ExplicitSymbolsDeleter {
~ExplicitSymbolsDeleter() {
delete ExplicitSymbols;
}
};
}
static ExplicitSymbolsDeleter Dummy;
static llvm::sys::SmartMutex<true>& getMutex() {
static llvm::sys::SmartMutex<true> HandlesMutex;
return HandlesMutex;
}
void llvm::sys::DynamicLibrary::AddSymbol(StringRef symbolName,
void *symbolValue) {
SmartScopedLock<true> lock(*SymbolsMutex);
SmartScopedLock<true> lock(getMutex());
if (ExplicitSymbols == 0)
ExplicitSymbols = new StringMap<void*>();
(*ExplicitSymbols)[symbolName] = symbolValue;
}
@ -54,7 +72,7 @@ static DenseSet<void *> *OpenedHandles = 0;
DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
std::string *errMsg) {
SmartScopedLock<true> lock(*SymbolsMutex);
SmartScopedLock<true> lock(getMutex());
void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
if (handle == 0) {
@ -108,10 +126,10 @@ void *SearchForAddressOfSpecialSymbol(const char* symbolName);
}
void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
SmartScopedLock<true> Lock(*SymbolsMutex);
SmartScopedLock<true> Lock(getMutex());
// First check symbols added via AddSymbol().
if (ExplicitSymbols.isConstructed()) {
if (ExplicitSymbols) {
StringMap<void *>::iterator i = ExplicitSymbols->find(symbolName);
if (i != ExplicitSymbols->end())