From: Zachary Turner Date: Tue, 17 Jun 2014 00:17:38 +0000 (+0000) Subject: Expose ValueMap's mutex type as a typedef instead of a sys::Mutex. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=814a49385ce96ec18eb3b2f3f6be5e96cd71cca8;p=platform%2Fupstream%2Fllvm.git Expose ValueMap's mutex type as a typedef instead of a sys::Mutex. This enables static polymorphism of the mutex type, which is necessary in order to replace the standard mutex implementation with a different type. llvm-svn: 211080 --- diff --git a/llvm/include/llvm/IR/ValueMap.h b/llvm/include/llvm/IR/ValueMap.h index 1503aed..f196f33 100644 --- a/llvm/include/llvm/IR/ValueMap.h +++ b/llvm/include/llvm/IR/ValueMap.h @@ -45,8 +45,10 @@ class ValueMapConstIterator; /// This class defines the default behavior for configurable aspects of /// ValueMap<>. User Configs should inherit from this class to be as compatible /// as possible with future versions of ValueMap. -template +template struct ValueMapConfig { + typedef MutexT mutex_type; + /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's /// false, the ValueMap will leave the original mapping in place. enum { FollowRAUW = true }; @@ -67,7 +69,7 @@ struct ValueMapConfig { /// and onDelete) and not inside other ValueMap methods. NULL means that no /// mutex is necessary. template - static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return nullptr; } + static mutex_type *getMutex(const ExtraDataT &/*Data*/) { return nullptr; } }; /// See the file comment. @@ -212,7 +214,7 @@ public: void deleted() override { // Make a copy that won't get changed even when *this is destroyed. ValueMapCallbackVH Copy(*this); - sys::Mutex *M = Config::getMutex(Copy.Map->Data); + typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data); if (M) M->acquire(); Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this. @@ -225,7 +227,7 @@ public: "Invalid RAUW on key of ValueMap<>"); // Make a copy that won't get changed even when *this is destroyed. ValueMapCallbackVH Copy(*this); - sys::Mutex *M = Config::getMutex(Copy.Map->Data); + typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data); if (M) M->acquire(); diff --git a/llvm/unittests/IR/ValueMapTest.cpp b/llvm/unittests/IR/ValueMapTest.cpp index 3427c91..d480865 100644 --- a/llvm/unittests/IR/ValueMapTest.cpp +++ b/llvm/unittests/IR/ValueMapTest.cpp @@ -177,10 +177,10 @@ TYPED_TEST(ValueMapTest, ConfiguredCollisionBehavior) { // TODO: Implement this when someone needs it. } -template -struct LockMutex : ValueMapConfig { +template +struct LockMutex : ValueMapConfig { struct ExtraData { - sys::Mutex *M; + mutex_type *M; bool *CalledRAUW; bool *CalledDeleted; }; @@ -192,15 +192,15 @@ struct LockMutex : ValueMapConfig { *Data.CalledDeleted = true; EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked."; } - static sys::Mutex *getMutex(const ExtraData &Data) { return Data.M; } + static mutex_type *getMutex(const ExtraData &Data) { return Data.M; } }; #if LLVM_ENABLE_THREADS TYPED_TEST(ValueMapTest, LocksMutex) { sys::Mutex M(false); // Not recursive. bool CalledRAUW = false, CalledDeleted = false; - typename LockMutex::ExtraData Data = - {&M, &CalledRAUW, &CalledDeleted}; - ValueMap > VM(Data); + typedef LockMutex ConfigType; + typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted}; + ValueMap VM(Data); VM[this->BitcastV.get()] = 7; this->BitcastV->replaceAllUsesWith(this->AddV.get()); this->AddV.reset();