Sort #include lines
[folly.git] / folly / experimental / hazptr / test / HazptrTest.cpp
index d40e9275fe75363419aa23abb2eb716c49831202..d8ca18dacf7ad406bab73c24aeadbd07d3b021b6 100644 (file)
 #define HAZPTR_STATS true
 #define HAZPTR_SCAN_THRESHOLD 10
 
-#include <folly/experimental/hazptr/test/HazptrUse1.h>
-#include <folly/experimental/hazptr/test/HazptrUse2.h>
+#include <folly/experimental/hazptr/debug.h>
 #include <folly/experimental/hazptr/example/LockFreeLIFO.h>
 #include <folly/experimental/hazptr/example/SWMRList.h>
 #include <folly/experimental/hazptr/example/WideCAS.h>
-#include <folly/experimental/hazptr/debug.h>
 #include <folly/experimental/hazptr/hazptr.h>
+#include <folly/experimental/hazptr/test/HazptrUse1.h>
+#include <folly/experimental/hazptr/test/HazptrUse2.h>
 
 #include <folly/portability/GFlags.h>
 #include <folly/portability/GTest.h>
@@ -262,23 +262,32 @@ TEST_F(HazptrTest, VirtualTest) {
   }
 }
 
-TEST_F(HazptrTest, DestructionTest) {
-  hazptr_domain myDomain0;
+void destructionTest(hazptr_domain& domain) {
   struct Thing : public hazptr_obj_base<Thing> {
     Thing* next;
-    Thing(Thing* n) : next(n) {}
+    hazptr_domain* domain;
+    int val;
+    Thing(int v, Thing* n, hazptr_domain* d) : next(n), domain(d), val(v) {}
     ~Thing() {
-      DEBUG_PRINT("this: " << this << " next: " << next);
+      DEBUG_PRINT("this: " << this << " val: " << val << " next: " << next);
       if (next) {
-        next->retire();
+        next->retire(*domain);
       }
     }
   };
   Thing* last{nullptr};
   for (int i = 0; i < 2000; i++) {
-    last = new Thing(last);
+    last = new Thing(i, last, &domain);
+  }
+  last->retire(domain);
+}
+
+TEST_F(HazptrTest, DestructionTest) {
+  {
+    hazptr_domain myDomain0;
+    destructionTest(myDomain0);
   }
-  last->retire();
+  destructionTest(default_hazptr_domain());
 }
 
 TEST_F(HazptrTest, Move) {