Rewrites barrier driver
[libcds.git] / test / stress / misc / barrier_driver.cpp
index e21f9f7acaab8993ac162ef03b554e218ed82a70..8dfc41dc8fef3502d23642845f4b8e312dc10157 100644 (file)
@@ -1,9 +1,12 @@
+#include "common.h"
 #include <atomic>
 #include <cds/gc/dhp.h>
 #include <cds/gc/hp.h>
-#include <cds/sync/barrier.h>
+#include <cds/misc/barrier.h>
 #include <cds_test/stress_test.h>
 #include <iostream>
+#include <memory>
+#include <vector>
 #include <thread>
 
 using namespace std;
@@ -12,45 +15,44 @@ namespace {
 
 typedef cds_others::SpinBarrier Barrier;
 
+static size_t s_nBarrierThreadCount = 2;
+static size_t s_nBarrierPassCount = 100000000;
+
 class BarrierTest : public cds_test::stress_fixture {
 protected:
   static Barrier *barrier;
-  static int count;
-  static const int kThreads = 6;
-  static const int kPassCount = 10000;
-
-  static void SetUpTestCase() {}
+  static size_t count;
 
-  static void TearDownTestCase() {
-    assert (count == kPassCount*kPassCount);
+  static void SetUpTestCase() {
+    cds_test::config const &cfg = get_config("Misc");
+    GetConfig(BarrierPassCount);
+    GetConfig(BarrierThreadCount);
   }
 
   static void Thread() {
-    for (int i = 0; i < kPassCount; i++) {
-      for (int j = 0; j < kPassCount; j++) {
-        if (barrier->wait()) {
-          count++;
-        }
+    for (size_t i = 0; i < s_nBarrierPassCount; i++) {
+      if (barrier->wait()) {
+        count++;
       }
     }
   }
 };
 
 Barrier *BarrierTest::barrier;
-int BarrierTest::count;
-const int BarrierTest::kThreads;
+size_t BarrierTest::count;
 
 TEST_F(BarrierTest, Wait) {
-  barrier = new Barrier(kThreads);
-  int num_threads = kThreads;
-  std::thread *threads = new std::thread[num_threads];
-  for (int i = 0; i < num_threads; i++) {
-    threads[i] = std::thread(Thread);
+  barrier = new Barrier(s_nBarrierThreadCount);
+  std::vector<std::thread> threads;
+  for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
+    threads.push_back(std::thread(Thread));
   }
 
-  for (int i = 0; i < num_threads; i++) {
+  for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
     threads[i].join();
   }
+  EXPECT_EQ(count, s_nBarrierPassCount);
+  delete barrier;
 }
 
 } // namespace