Refactors some of existing cds multi-threaded stress test cases
[libcds.git] / test / stress / misc / seqlock_driver.cpp
index abf2583701ff72198edad7a494bcf69330b48665..cbe54e1fe21d1422a1247a372e56f7074cda87b7 100644 (file)
@@ -2,9 +2,10 @@
 #include <atomic>
 #include <cds/gc/dhp.h>
 #include <cds/gc/hp.h>
-#include <cds/sync/seqlock.h>
+#include <cds/misc/seqlock.h>
 #include <cds_test/stress_test.h>
 #include <iostream>
+#include <memory>
 #include <thread>
 
 using namespace std;
@@ -13,16 +14,13 @@ namespace {
 
 typedef cds_others::SeqLock SeqLock;
 
-static size_t s_nSeqLockReaderWriterThreadCount = 6;
+static size_t s_nSeqLockReaderWriterThreadCount = 4;
 static size_t s_nSeqLockPassCount = 2000000;
 
 class SeqLockTest : public cds_test::stress_fixture {
 protected:
-  static int sum;
+  static size_t sum;
   static SeqLock *seqlock;
-  static const int kReaderThreads = 0;
-  static const int kWriterThreads = 0;
-  static const int kWriterPercentage = 15;
 
   static void SetUpTestCase() {
     cds_test::config const &cfg = get_config("Misc");
@@ -30,12 +28,8 @@ protected:
     GetConfig(SeqLockPassCount);
   }
 
-  static void ReaderThread() {}
-
-  static void WriterThread() {}
-
   static void ReaderWriterThread(int write_percentage) {
-    for (int i = 0; i < s_nSeqLockPassCount; i++) {
+    for (size_t i = 0; i < s_nSeqLockPassCount; i++) {
       if (rand(100) < write_percentage) {
         sum += seqlock->read();
       } else {
@@ -45,20 +39,20 @@ protected:
   }
 };
 
-int SeqLockTest::sum;
+size_t SeqLockTest::sum;
 SeqLock *SeqLockTest::seqlock;
 
 TEST_F(SeqLockTest, BasicReadWriter) {
   seqlock = new SeqLock();
   for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
-    std::thread *threads = new std::thread[s_nSeqLockReaderWriterThreadCount];
+    std::unique_ptr<std::thread[]> threads(
+        new std::thread[s_nSeqLockReaderWriterThreadCount]);
     for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
       threads[i] = std::thread(ReaderWriterThread, write_percentage);
     }
-    for (int i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
+    for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
       threads[i].join();
     }
-    delete[] threads;
   }
 }