diff options
author | Dwight <dwight@10gen.com> | 2011-01-04 16:14:31 -0500 |
---|---|---|
committer | Dwight <dwight@10gen.com> | 2011-01-04 17:44:35 -0500 |
commit | 8b9a74f6a61ed01f57a59dbc30ed69f3d1b8456f (patch) | |
tree | d97c629513620aa2ec98f02738621e47bfdb008f /dbtests | |
parent | 5a4217538fc8dc370862b25ed15a0333d4c8e058 (diff) | |
download | mongo-8b9a74f6a61ed01f57a59dbc30ed69f3d1b8456f.tar.gz |
add a mongomutextest
Diffstat (limited to 'dbtests')
-rw-r--r-- | dbtests/threadedtests.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/dbtests/threadedtests.cpp b/dbtests/threadedtests.cpp index 8891594537c..5c94067d591 100644 --- a/dbtests/threadedtests.cpp +++ b/dbtests/threadedtests.cpp @@ -39,9 +39,7 @@ namespace ThreadedTests { void run() { setup(); - launch_subthreads(nthreads); - validate(); } @@ -59,6 +57,72 @@ namespace ThreadedTests { } }; + class MongoMutexTest : public ThreadedTest<> { + enum { N = 1000000 }; + MongoMutex *mm; + virtual void setup() { + mm = new MongoMutex("MongoMutexTest"); + } + virtual void subthread() { + Client::initThread("mongomutextest"); + sleepmillis(0); + for( int i = 0; i < N; i++ ) { + if( i % 20000 == 0 ) + log() << i << endl; + if( i % 7 == 0 ) { + mm->lock_shared(); + mm->lock_shared(); + mm->unlock_shared(); + mm->unlock_shared(); + } + else if( i % 7 == 1 ) { + mm->lock_shared(); + ASSERT( mm->atLeastReadLocked() ); + mm->unlock_shared(); + } + else if( i % 7 == 2 ) { + mm->lock(); + ASSERT( mm->isWriteLocked() ); + mm->unlock(); + } + else if( i % 7 == 3 ) { + mm->lock(); + mm->lock_shared(); + ASSERT( mm->isWriteLocked() ); + mm->unlock_shared(); + mm->unlock(); + } + else if( i % 7 == 4 ) { + mm->lock(); + mm->releaseEarly(); + mm->unlock(); + } + else if( i % 7 == 5 ) { + if( mm->lock_try(1) ) { + mm->unlock(); + } + } + else if( i % 7 == 6 ) { + if( mm->lock_shared_try(0) ) { + mm->unlock_shared(); + } + } + else { + mm->lock_shared(); + mm->unlock_shared(); + } + } + cc().shutdown(); + } + virtual void validate() { + ASSERT( !mm->atLeastReadLocked() ); + mm->lock(); + mm->unlock(); + mm->lock_shared(); + mm->unlock_shared(); + } + }; + // Tested with up to 30k threads class IsAtomicUIntAtomic : public ThreadedTest<> { static const int iterations = 1000000; @@ -153,6 +217,7 @@ namespace ThreadedTests { add< MVarTest >(); add< ThreadPoolTest >(); add< LockTest >(); + add< MongoMutexTest >(); } } myall; } |