[llvm-commits] [llvm] r118463 - /llvm/trunk/lib/System/DynamicLibrary.cpp

Owen Anderson resistor at mac.com
Tue Nov 9 09:51:02 PST 2010


On Nov 8, 2010, at 10:07 PM, Chris Lattner wrote:

> 
> On Nov 8, 2010, at 4:36 PM, Owen Anderson wrote:
> 
>> Author: resistor
>> Date: Mon Nov  8 18:36:06 2010
>> New Revision: 118463
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=118463&view=rev
>> Log:
>> Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.
> 
> Hi Owen,
> 
> Does SmartMutex<true> cause a static constructor?

Yes, as does sys::Mutex.  Unfortunately, we can't use ManagedStatic here because it would introduce a circular dependency (System --> Support --> System).  I feel like we tried to move ManagedStatic to System at some point in the past, and that it didn't work out, but I don't remember why.

--Owen

> 
>> 
>> Modified:
>>   llvm/trunk/lib/System/DynamicLibrary.cpp
>> 
>> Modified: llvm/trunk/lib/System/DynamicLibrary.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=118463&r1=118462&r2=118463&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/System/DynamicLibrary.cpp (original)
>> +++ llvm/trunk/lib/System/DynamicLibrary.cpp Mon Nov  8 18:36:06 2010
>> @@ -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 @@
>> //===          independent code.
>> //===----------------------------------------------------------------------===//
>> 
>> +static SmartMutex<true> HandlesMutex;
>> static std::vector<void *> *OpenedHandles = 0;
>> 
>> 
>> @@ -76,6 +78,7 @@
>>  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 @@
>> 
>> #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) {
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101109/e219ff4a/attachment.html>


More information about the llvm-commits mailing list