diff options
| author | Owen Anderson <resistor@mac.com> | 2010-11-18 18:49:05 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2010-11-18 18:49:05 +0000 |
| commit | aa398c1617d6ebb5e6a3b3d2c0c7a98e8693525f (patch) | |
| tree | 0e0eaa7a33c4837238caeb02cd27f9ea9e75182b /llvm/lib | |
| parent | e4f7ec17f87d4eaed40a63496f73a1acd2454e2f (diff) | |
| download | bcm5719-llvm-aa398c1617d6ebb5e6a3b3d2c0c7a98e8693525f.tar.gz bcm5719-llvm-aa398c1617d6ebb5e6a3b3d2c0c7a98e8693525f.zip | |
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.
llvm-svn: 119718
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/System/DynamicLibrary.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/lib/System/DynamicLibrary.cpp b/llvm/lib/System/DynamicLibrary.cpp index 3da50a28b65..33f86334e38 100644 --- a/llvm/lib/System/DynamicLibrary.cpp +++ b/llvm/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) { |

