diff options
author | Owen Anderson <resistor@mac.com> | 2010-11-09 00:36:06 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-11-09 00:36:06 +0000 |
commit | 9ac18d562d9839e881165e8f8a25d87b9f8279e8 (patch) | |
tree | 6ac1dcc9067226f95fe0ee666d207f4e7c69b520 | |
parent | 5e559a22c18166508a01fbd65471ec4e752726f9 (diff) |
Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118463 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/System/DynamicLibrary.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/System/DynamicLibrary.cpp b/lib/System/DynamicLibrary.cpp index 660db492d6..3da50a28b6 100644 --- a/lib/System/DynamicLibrary.cpp +++ b/lib/System/DynamicLibrary.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "llvm/System/DynamicLibrary.h" +#include "llvm/System/Mutex.h" #include "llvm/Config/config.h" #include <cstdio> #include <cstring> @@ -60,6 +61,7 @@ using namespace llvm::sys; //=== independent code. //===----------------------------------------------------------------------===// +static SmartMutex<true> HandlesMutex; static std::vector<void *> *OpenedHandles = 0; @@ -76,6 +78,7 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename, if (Filename == NULL) H = RTLD_DEFAULT; #endif + SmartScopedLock<true> Lock(HandlesMutex); if (OpenedHandles == 0) OpenedHandles = new std::vector<void *>(); OpenedHandles->push_back(H); @@ -110,6 +113,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) { #if HAVE_DLFCN_H // Now search the libraries. + SmartScopedLock<true> Lock(HandlesMutex); if (OpenedHandles) { for (std::vector<void *>::iterator I = OpenedHandles->begin(), E = OpenedHandles->end(); I != E; ++I) { |