summaryrefslogtreecommitdiff
path: root/src/mongo/util/concurrency/spin_lock_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/concurrency/spin_lock_test.cpp')
-rw-r--r--src/mongo/util/concurrency/spin_lock_test.cpp118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/mongo/util/concurrency/spin_lock_test.cpp b/src/mongo/util/concurrency/spin_lock_test.cpp
index 9fef554f352..8a2e1f47cec 100644
--- a/src/mongo/util/concurrency/spin_lock_test.cpp
+++ b/src/mongo/util/concurrency/spin_lock_test.cpp
@@ -34,81 +34,81 @@
namespace {
- using mongo::SpinLock;
- using mongo::Timer;
+using mongo::SpinLock;
+using mongo::Timer;
- namespace stdx = mongo::stdx;
+namespace stdx = mongo::stdx;
- class LockTester {
- public:
- LockTester( SpinLock* spin, int* counter )
- : _spin(spin), _counter(counter), _requests(0) {}
+class LockTester {
+public:
+ LockTester(SpinLock* spin, int* counter) : _spin(spin), _counter(counter), _requests(0) {}
- ~LockTester() {
- delete _t;
- }
+ ~LockTester() {
+ delete _t;
+ }
- void start( int increments ) {
- _t = new stdx::thread( mongo::stdx::bind(&LockTester::test, this, increments) );
- }
+ void start(int increments) {
+ _t = new stdx::thread(mongo::stdx::bind(&LockTester::test, this, increments));
+ }
- void join() {
- if ( _t ) _t->join();
- }
+ void join() {
+ if (_t)
+ _t->join();
+ }
- int requests() const {
- return _requests;
- }
+ int requests() const {
+ return _requests;
+ }
- private:
- SpinLock* _spin; // not owned here
- int* _counter; // not owned here
- int _requests;
- stdx::thread* _t;
-
- void test( int increments ) {
- while ( increments-- > 0 ) {
- _spin->lock();
- ++(*_counter);
- ++_requests;
- _spin->unlock();
- }
+private:
+ SpinLock* _spin; // not owned here
+ int* _counter; // not owned here
+ int _requests;
+ stdx::thread* _t;
+
+ void test(int increments) {
+ while (increments-- > 0) {
+ _spin->lock();
+ ++(*_counter);
+ ++_requests;
+ _spin->unlock();
}
+ }
- LockTester( LockTester& );
- LockTester& operator=( LockTester& );
- };
+ LockTester(LockTester&);
+ LockTester& operator=(LockTester&);
+};
- TEST(Concurrency, ConcurrentIncs) {
- SpinLock spin;
- int counter = 0;
+TEST(Concurrency, ConcurrentIncs) {
+ SpinLock spin;
+ int counter = 0;
- const int threads = 64;
- const int incs = 50000;
- LockTester* testers[threads];
+ const int threads = 64;
+ const int incs = 50000;
+ LockTester* testers[threads];
- Timer timer;
+ Timer timer;
- for ( int i = 0; i < threads; i++ ) {
- testers[i] = new LockTester( &spin, &counter );
- }
- for ( int i = 0; i < threads; i++ ) {
- testers[i]->start( incs );
- }
- for ( int i = 0; i < threads; i++ ) {
- testers[i]->join();
- ASSERT_EQUALS( testers[i]->requests(), incs );
- delete testers[i];
- }
+ for (int i = 0; i < threads; i++) {
+ testers[i] = new LockTester(&spin, &counter);
+ }
+ for (int i = 0; i < threads; i++) {
+ testers[i]->start(incs);
+ }
+ for (int i = 0; i < threads; i++) {
+ testers[i]->join();
+ ASSERT_EQUALS(testers[i]->requests(), incs);
+ delete testers[i];
+ }
- int ms = timer.millis();
- mongo::unittest::log() << "spinlock ConcurrentIncs time: " << ms << std::endl;
+ int ms = timer.millis();
+ mongo::unittest::log() << "spinlock ConcurrentIncs time: " << ms << std::endl;
- ASSERT_EQUALS( counter, threads*incs );
+ ASSERT_EQUALS(counter, threads * incs);
#if defined(__linux__)
- ASSERT( SpinLock::isfast() );
+ ASSERT(SpinLock::isfast());
#endif
- }
+}
-} // namespace
+} // namespace