<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 8, 2010, at 10:07 PM, Chris Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Nov 8, 2010, at 4:36 PM, Owen Anderson wrote:<br><br><blockquote type="cite">Author: resistor<br></blockquote><blockquote type="cite">Date: Mon Nov  8 18:36:06 2010<br></blockquote><blockquote type="cite">New Revision: 118463<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=118463&view=rev">http://llvm.org/viewvc/llvm-project?rev=118463&view=rev</a><br></blockquote><blockquote type="cite">Log:<br></blockquote><blockquote type="cite">Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.<br></blockquote><br>Hi Owen,<br><br>Does SmartMutex<true> cause a static constructor?<br></div></blockquote><div><br></div><div>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.</div><div><br></div><div>--Owen</div><br><blockquote type="cite"><div><br><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified:<br></blockquote><blockquote type="cite">   llvm/trunk/lib/System/DynamicLibrary.cpp<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified: llvm/trunk/lib/System/DynamicLibrary.cpp<br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=118463&r1=118462&r2=118463&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=118463&r1=118462&r2=118463&view=diff</a><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/lib/System/DynamicLibrary.cpp (original)<br></blockquote><blockquote type="cite">+++ llvm/trunk/lib/System/DynamicLibrary.cpp Mon Nov  8 18:36:06 2010<br></blockquote><blockquote type="cite">@@ -15,6 +15,7 @@<br></blockquote><blockquote type="cite">//===----------------------------------------------------------------------===//<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">#include "llvm/System/DynamicLibrary.h"<br></blockquote><blockquote type="cite">+#include "llvm/System/Mutex.h"<br></blockquote><blockquote type="cite">#include "llvm/Config/config.h"<br></blockquote><blockquote type="cite">#include <cstdio><br></blockquote><blockquote type="cite">#include <cstring><br></blockquote><blockquote type="cite">@@ -60,6 +61,7 @@<br></blockquote><blockquote type="cite">//===          independent code.<br></blockquote><blockquote type="cite">//===----------------------------------------------------------------------===//<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+static SmartMutex<true> HandlesMutex;<br></blockquote><blockquote type="cite">static std::vector<void *> *OpenedHandles = 0;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">@@ -76,6 +78,7 @@<br></blockquote><blockquote type="cite">  if (Filename == NULL)<br></blockquote><blockquote type="cite">    H = RTLD_DEFAULT;<br></blockquote><blockquote type="cite">#endif<br></blockquote><blockquote type="cite">+  SmartScopedLock<true> Lock(HandlesMutex);<br></blockquote><blockquote type="cite">  if (OpenedHandles == 0)<br></blockquote><blockquote type="cite">    OpenedHandles = new std::vector<void *>();<br></blockquote><blockquote type="cite">  OpenedHandles->push_back(H);<br></blockquote><blockquote type="cite">@@ -110,6 +113,7 @@<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">#if HAVE_DLFCN_H<br></blockquote><blockquote type="cite">  // Now search the libraries.<br></blockquote><blockquote type="cite">+  SmartScopedLock<true> Lock(HandlesMutex);<br></blockquote><blockquote type="cite">  if (OpenedHandles) {<br></blockquote><blockquote type="cite">    for (std::vector<void *>::iterator I = OpenedHandles->begin(),<br></blockquote><blockquote type="cite">         E = OpenedHandles->end(); I != E; ++I) {<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">llvm-commits mailing list<br></blockquote><blockquote type="cite"><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote><br></div></blockquote></div><br></body></html>