Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 84fea77

Browse files
author
Zachary Turner
committed
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211080 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 408691f commit 84fea77

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

include/llvm/IR/ValueMap.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ class ValueMapConstIterator;
4545
/// This class defines the default behavior for configurable aspects of
4646
/// ValueMap<>. User Configs should inherit from this class to be as compatible
4747
/// as possible with future versions of ValueMap.
48-
template<typename KeyT>
48+
template<typename KeyT, typename MutexT = sys::Mutex>
4949
struct ValueMapConfig {
50+
typedef MutexT mutex_type;
51+
5052
/// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's
5153
/// false, the ValueMap will leave the original mapping in place.
5254
enum { FollowRAUW = true };
@@ -67,7 +69,7 @@ struct ValueMapConfig {
6769
/// and onDelete) and not inside other ValueMap methods. NULL means that no
6870
/// mutex is necessary.
6971
template<typename ExtraDataT>
70-
static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return nullptr; }
72+
static mutex_type *getMutex(const ExtraDataT &/*Data*/) { return nullptr; }
7173
};
7274

7375
/// See the file comment.
@@ -212,7 +214,7 @@ class ValueMapCallbackVH : public CallbackVH {
212214
void deleted() override {
213215
// Make a copy that won't get changed even when *this is destroyed.
214216
ValueMapCallbackVH Copy(*this);
215-
sys::Mutex *M = Config::getMutex(Copy.Map->Data);
217+
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
216218
if (M)
217219
M->acquire();
218220
Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
@@ -225,7 +227,7 @@ class ValueMapCallbackVH : public CallbackVH {
225227
"Invalid RAUW on key of ValueMap<>");
226228
// Make a copy that won't get changed even when *this is destroyed.
227229
ValueMapCallbackVH Copy(*this);
228-
sys::Mutex *M = Config::getMutex(Copy.Map->Data);
230+
typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
229231
if (M)
230232
M->acquire();
231233

unittests/IR/ValueMapTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ TYPED_TEST(ValueMapTest, ConfiguredCollisionBehavior) {
177177
// TODO: Implement this when someone needs it.
178178
}
179179

180-
template<typename KeyT>
181-
struct LockMutex : ValueMapConfig<KeyT> {
180+
template<typename KeyT, typename MutexT>
181+
struct LockMutex : ValueMapConfig<KeyT, MutexT> {
182182
struct ExtraData {
183-
sys::Mutex *M;
183+
mutex_type *M;
184184
bool *CalledRAUW;
185185
bool *CalledDeleted;
186186
};
@@ -192,15 +192,15 @@ struct LockMutex : ValueMapConfig<KeyT> {
192192
*Data.CalledDeleted = true;
193193
EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
194194
}
195-
static sys::Mutex *getMutex(const ExtraData &Data) { return Data.M; }
195+
static mutex_type *getMutex(const ExtraData &Data) { return Data.M; }
196196
};
197197
#if LLVM_ENABLE_THREADS
198198
TYPED_TEST(ValueMapTest, LocksMutex) {
199199
sys::Mutex M(false); // Not recursive.
200200
bool CalledRAUW = false, CalledDeleted = false;
201-
typename LockMutex<TypeParam*>::ExtraData Data =
202-
{&M, &CalledRAUW, &CalledDeleted};
203-
ValueMap<TypeParam*, int, LockMutex<TypeParam*> > VM(Data);
201+
typedef LockMutex<TypeParam*, sys::Mutex> ConfigType;
202+
typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted};
203+
ValueMap<TypeParam*, int, ConfigType> VM(Data);
204204
VM[this->BitcastV.get()] = 7;
205205
this->BitcastV->replaceAllUsesWith(this->AddV.get());
206206
this->AddV.reset();

0 commit comments

Comments
 (0)