summaryrefslogtreecommitdiff
path: root/dbtests/threadedtests.cpp
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-03-25 19:21:32 +0100
committerAntonin Kral <a.kral@bobek.cz>2010-03-25 19:21:32 +0100
commit0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 (patch)
tree2b3886e435b0217d6afd63a213b04d32bb4b4f6f /dbtests/threadedtests.cpp
parenta696359b248adef0cc8576fce3f473535e995136 (diff)
downloadmongodb-0ca01a91ae0a3562e54c226e7b9512feb2ea83d0.tar.gz
Imported Upstream version 1.4.0
Diffstat (limited to 'dbtests/threadedtests.cpp')
-rw-r--r--dbtests/threadedtests.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/dbtests/threadedtests.cpp b/dbtests/threadedtests.cpp
index f3ebe39..2ffafba 100644
--- a/dbtests/threadedtests.cpp
+++ b/dbtests/threadedtests.cpp
@@ -18,6 +18,7 @@
*/
#include "stdafx.h"
+#include "../util/atomic_int.h"
#include "../util/mvar.h"
#include "../util/thread_pool.h"
#include <boost/thread.hpp>
@@ -59,18 +60,26 @@ namespace ThreadedTests {
};
// Tested with up to 30k threads
- class IsWrappingIntAtomic : public ThreadedTest<> {
+ class IsAtomicUIntAtomic : public ThreadedTest<> {
static const int iterations = 1000000;
- WrappingInt target;
+ AtomicUInt target;
void subthread(){
for(int i=0; i < iterations; i++){
//target.x++; // verified to fail with this version
- target.atomicIncrement();
+ target++;
}
}
void validate(){
ASSERT_EQUALS(target.x , unsigned(nthreads * iterations));
+
+ AtomicUInt u;
+ ASSERT_EQUALS(0u, u);
+ ASSERT_EQUALS(0u, u++);
+ ASSERT_EQUALS(2u, ++u);
+ ASSERT_EQUALS(2u, u--);
+ ASSERT_EQUALS(0u, --u);
+ ASSERT_EQUALS(0u, u);
}
};
@@ -99,10 +108,10 @@ namespace ThreadedTests {
static const int iterations = 10000;
static const int nThreads = 8;
- WrappingInt counter;
+ AtomicUInt counter;
void increment(int n){
for (int i=0; i<n; i++){
- counter.atomicIncrement();
+ counter++;
}
}
@@ -111,13 +120,12 @@ namespace ThreadedTests {
ThreadPool tp(nThreads);
for (int i=0; i < iterations; i++){
- tp.schedule(&WrappingInt::atomicIncrement, &counter);
tp.schedule(&ThreadPoolTest::increment, this, 2);
}
tp.join();
- ASSERT(counter == (unsigned)(iterations * 3));
+ ASSERT(counter == (unsigned)(iterations * 2));
}
};
@@ -127,7 +135,7 @@ namespace ThreadedTests {
}
void setupTests(){
- add< IsWrappingIntAtomic >();
+ add< IsAtomicUIntAtomic >();
add< MVarTest >();
add< ThreadPoolTest >();
}