[compiler-rt] r202278 - tsan: fix deadlock detector test so that it does not force contention in runtime
Dmitry Vyukov
dvyukov at google.com
Wed Feb 26 09:06:58 PST 2014
Author: dvyukov
Date: Wed Feb 26 11:06:58 2014
New Revision: 202278
URL: http://llvm.org/viewvc/llvm-project?rev=202278&view=rev
Log:
tsan: fix deadlock detector test so that it does not force contention in runtime
Modified:
compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc
Modified: compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc?rev=202278&r1=202277&r2=202278&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc (original)
+++ compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc Wed Feb 26 11:06:58 2014
@@ -88,36 +88,44 @@ class PthreadRWLock {
class LockTest {
public:
- explicit LockTest(size_t n) : n_(n), locks_(new LockType[n]) { }
- ~LockTest() { delete [] locks_; }
+ explicit LockTest(size_t n)
+ : n_(n), locks_(new LockType*[n]) {
+ for (size_t i = 0; i < n_; i++)
+ locks_[i] = new LockType;
+ }
+ ~LockTest() {
+ for (size_t i = 0; i < n_; i++)
+ delete locks_[i];
+ delete [] locks_;
+ }
void L(size_t i) {
assert(i < n_);
- locks_[i].lock();
+ locks_[i]->lock();
}
void U(size_t i) {
assert(i < n_);
- locks_[i].unlock();
+ locks_[i]->unlock();
}
void RL(size_t i) {
assert(i < n_);
- locks_[i].rdlock();
+ locks_[i]->rdlock();
}
void RU(size_t i) {
assert(i < n_);
- locks_[i].rdunlock();
+ locks_[i]->rdunlock();
}
void *A(size_t i) {
assert(i < n_);
- return &locks_[i];
+ return locks_[i];
}
bool T(size_t i) {
assert(i < n_);
- return locks_[i].try_lock();
+ return locks_[i]->try_lock();
}
// Simple lock order onversion.
@@ -263,12 +271,13 @@ class LockTest {
// fprintf(stderr, "\n");
}
void Lock1_Loop_0() { Lock1_Loop(0, 100000); }
- void Lock1_Loop_1() { Lock1_Loop(1, 100000); }
- void Lock1_Loop_2() { Lock1_Loop(2, 100000); }
+ void Lock1_Loop_1() { Lock1_Loop(10, 100000); }
+ void Lock1_Loop_2() { Lock1_Loop(20, 100000); }
void CreateAndDestroyManyLocks() {
LockType create_many_locks_but_never_acquire[kDeadlockGraphSize];
(void)create_many_locks_but_never_acquire;
+ (void)create_many_locks_but_never_acquire;
}
void CreateLockUnlockAndDestroyManyLocks() {
@@ -305,7 +314,7 @@ class LockTest {
static const size_t kDeadlockGraphSize = 4096;
size_t n_;
- LockType *locks_;
+ LockType **locks_;
};
int main() {
@@ -314,7 +323,7 @@ int main() {
{ LockTest t(5); t.Test3(); }
{ LockTest t(5); t.Test4(); }
{ LockTest t(5); t.Test5(); }
- { LockTest t(5); t.Test6(); }
+ { LockTest t(100); t.Test6(); }
{ LockTest t(10); t.Test7(); }
{ LockTest t(5); t.Test8(); }
{ LockTest t(5); t.Test9(); }
More information about the llvm-commits
mailing list