aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-11-18 18:49:05 +0000
committerOwen Anderson <resistor@mac.com>2010-11-18 18:49:05 +0000
commit27cb5e612ae280a0084a2c608cc8b13786431b7d (patch)
tree67cc1b38d4132b9cfc8cb04e231ea76a08fce152
parentbd77d399c4cdc2440abde96b2861b149fae4f33e (diff)
downloadexternal_llvm-27cb5e612ae280a0084a2c608cc8b13786431b7d.zip
external_llvm-27cb5e612ae280a0084a2c608cc8b13786431b7d.tar.gz
external_llvm-27cb5e612ae280a0084a2c608cc8b13786431b7d.tar.bz2
Use thread-safe statics to avoid a static constructor here. This isn't thread-safe on MSVC, but we don't
support threaded LLVM there anyways. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119718 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/System/DynamicLibrary.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/System/DynamicLibrary.cpp b/lib/System/DynamicLibrary.cpp
index 3da50a2..33f8633 100644
--- a/lib/System/DynamicLibrary.cpp
+++ b/lib/System/DynamicLibrary.cpp
@@ -61,9 +61,19 @@ using namespace llvm::sys;
//=== independent code.
//===----------------------------------------------------------------------===//
-static SmartMutex<true> HandlesMutex;
+static SmartMutex<true>* HandlesMutex;
static std::vector<void *> *OpenedHandles = 0;
+static bool InitializeMutex() {
+ HandlesMutex = new SmartMutex<true>;
+ return HandlesMutex != 0;
+}
+
+static bool EnsureMutexInitialized() {
+ static bool result = InitializeMutex();
+ return result;
+}
+
bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
std::string *ErrMsg) {
@@ -78,7 +88,8 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
if (Filename == NULL)
H = RTLD_DEFAULT;
#endif
- SmartScopedLock<true> Lock(HandlesMutex);
+ EnsureMutexInitialized();
+ SmartScopedLock<true> Lock(*HandlesMutex);
if (OpenedHandles == 0)
OpenedHandles = new std::vector<void *>();
OpenedHandles->push_back(H);
@@ -113,7 +124,8 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
#if HAVE_DLFCN_H
// Now search the libraries.
- SmartScopedLock<true> Lock(HandlesMutex);
+ EnsureMutexInitialized();
+ SmartScopedLock<true> Lock(*HandlesMutex);
if (OpenedHandles) {
for (std::vector<void *>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) {