Refactors some of existing cds multi-threaded stress test cases
[libcds.git] / test / stress / misc / rwlock_driver.cpp
index 7d0084d96f5b6206def3af3adc594335f0c0afb3..71581e4311449927bc77df0acd94fdb99d3af45e 100644 (file)
@@ -2,23 +2,24 @@
 #include <atomic>
 #include <cds/gc/dhp.h>
 #include <cds/gc/hp.h>
-#include <cds/sync/rwlock.h>
+#include <cds/misc/rwlock.h>
 #include <cds_test/stress_test.h>
 #include <iostream>
+#include <memory>
 #include <thread>
 
 using namespace std;
 
 namespace {
 
-static size_t s_nRWLockThreadCount = 6;
+static size_t s_nRWLockThreadCount = 4;
 static size_t s_nRWLockPassCount = 200000;
 
 typedef cds_others::RWLock RWLock;
 class RWLockTest : public cds_test::stress_fixture {
 protected:
-  static int sum;
-  static int x;
+  static size_t sum;
+  static size_t x;
   static RWLock *rwlock;
 
   static void SetUpTestCase() {
@@ -46,11 +47,11 @@ protected:
           if (!rwlock->write_trylock()) {
             rwlock->write_lock();
           }
-          x += 1;
+          x++;
           rwlock->write_unlock();
         } else {
           rwlock->write_lock();
-          x += 1;
+          x++;
           rwlock->write_unlock();
         }
       }
@@ -58,20 +59,20 @@ protected:
   }
 };
 
-int RWLockTest::x;
-int RWLockTest::sum;
+size_t RWLockTest::x;
+size_t RWLockTest::sum;
 RWLock *RWLockTest::rwlock;
 
 TEST_F(RWLockTest, BasicLockUnlock) {
   rwlock = new RWLock();
-  int num_threads = s_nRWLockThreadCount;
-  for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
-    std::thread *threads = new std::thread[num_threads];
+  size_t num_threads = s_nRWLockThreadCount;
+  for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
+    std::unique_ptr<std::thread[]> threads(new std::thread[num_threads]);
     for (size_t i = 0; i < num_threads; i++) {
       threads[i] = std::thread(ReaderWriterThread, write_percentage);
     }
 
-    for (int i = 0; i < num_threads; i++) {
+    for (size_t i = 0; i < num_threads; i++) {
       threads[i].join();
     }
   }