<p dir="ltr">I'm assuming this is so you can change smaller amounts of code/work incrementally, and at the end everything will be std::murex and this new template parameter can be removed?</p>
<div class="gmail_quote">On Jun 16, 2014 5:27 PM, "Zachary Turner" <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: zturner<br>
Date: Mon Jun 16 19:17:38 2014<br>
New Revision: 211080<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211080&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=211080&view=rev</a><br>
Log:<br>
Expose ValueMap's mutex type as a typedef instead of a sys::Mutex.<br>
<br>
This enables static polymorphism of the mutex type, which is<br>
necessary in order to replace the standard mutex implementation<br>
with a different type.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/ValueMap.h<br>
    llvm/trunk/unittests/IR/ValueMapTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/ValueMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ValueMap.h?rev=211080&r1=211079&r2=211080&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ValueMap.h?rev=211080&r1=211079&r2=211080&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/IR/ValueMap.h (original)<br>
+++ llvm/trunk/include/llvm/IR/ValueMap.h Mon Jun 16 19:17:38 2014<br>
@@ -45,8 +45,10 @@ class ValueMapConstIterator;<br>
 /// This class defines the default behavior for configurable aspects of<br>
 /// ValueMap<>.  User Configs should inherit from this class to be as compatible<br>
 /// as possible with future versions of ValueMap.<br>
-template<typename KeyT><br>
+template<typename KeyT, typename MutexT = sys::Mutex><br>
 struct ValueMapConfig {<br>
+  typedef MutexT mutex_type;<br>
+<br>
   /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's<br>
   /// false, the ValueMap will leave the original mapping in place.<br>
   enum { FollowRAUW = true };<br>
@@ -67,7 +69,7 @@ struct ValueMapConfig {<br>
   /// and onDelete) and not inside other ValueMap methods.  NULL means that no<br>
   /// mutex is necessary.<br>
   template<typename ExtraDataT><br>
-  static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return nullptr; }<br>
+  static mutex_type *getMutex(const ExtraDataT &/*Data*/) { return nullptr; }<br>
 };<br>
<br>
 /// See the file comment.<br>
@@ -212,7 +214,7 @@ public:<br>
   void deleted() override {<br>
     // Make a copy that won't get changed even when *this is destroyed.<br>
     ValueMapCallbackVH Copy(*this);<br>
-    sys::Mutex *M = Config::getMutex(Copy.Map->Data);<br>
+    typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);<br>
     if (M)<br>
       M->acquire();<br>
     Config::onDelete(Copy.Map->Data, Copy.Unwrap());  // May destroy *this.<br>
@@ -225,7 +227,7 @@ public:<br>
            "Invalid RAUW on key of ValueMap<>");<br>
     // Make a copy that won't get changed even when *this is destroyed.<br>
     ValueMapCallbackVH Copy(*this);<br>
-    sys::Mutex *M = Config::getMutex(Copy.Map->Data);<br>
+    typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);<br>
     if (M)<br>
       M->acquire();<br>
<br>
<br>
Modified: llvm/trunk/unittests/IR/ValueMapTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ValueMapTest.cpp?rev=211080&r1=211079&r2=211080&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ValueMapTest.cpp?rev=211080&r1=211079&r2=211080&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/unittests/IR/ValueMapTest.cpp (original)<br>
+++ llvm/trunk/unittests/IR/ValueMapTest.cpp Mon Jun 16 19:17:38 2014<br>
@@ -177,10 +177,10 @@ TYPED_TEST(ValueMapTest, ConfiguredColli<br>
   // TODO: Implement this when someone needs it.<br>
 }<br>
<br>
-template<typename KeyT><br>
-struct LockMutex : ValueMapConfig<KeyT> {<br>
+template<typename KeyT, typename MutexT><br>
+struct LockMutex : ValueMapConfig<KeyT, MutexT> {<br>
   struct ExtraData {<br>
-    sys::Mutex *M;<br>
+    mutex_type *M;<br>
     bool *CalledRAUW;<br>
     bool *CalledDeleted;<br>
   };<br>
@@ -192,15 +192,15 @@ struct LockMutex : ValueMapConfig<KeyT><br>
     *Data.CalledDeleted = true;<br>
     EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";<br>
   }<br>
-  static sys::Mutex *getMutex(const ExtraData &Data) { return Data.M; }<br>
+  static mutex_type *getMutex(const ExtraData &Data) { return Data.M; }<br>
 };<br>
 #if LLVM_ENABLE_THREADS<br>
 TYPED_TEST(ValueMapTest, LocksMutex) {<br>
   sys::Mutex M(false);  // Not recursive.<br>
   bool CalledRAUW = false, CalledDeleted = false;<br>
-  typename LockMutex<TypeParam*>::ExtraData Data =<br>
-    {&M, &CalledRAUW, &CalledDeleted};<br>
-  ValueMap<TypeParam*, int, LockMutex<TypeParam*> > VM(Data);<br>
+  typedef LockMutex<TypeParam*, sys::Mutex> ConfigType;<br>
+  typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted};<br>
+  ValueMap<TypeParam*, int, ConfigType> VM(Data);<br>
   VM[this->BitcastV.get()] = 7;<br>
   this->BitcastV->replaceAllUsesWith(this->AddV.get());<br>
   this->AddV.reset();<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>