Fixes RCU test cases error (loads should use Consume ordering)
[folly.git] / folly / stress-test / stress-sequential-folly-sync.cpp
index 9622230..5e39e42 100644 (file)
@@ -44,7 +44,7 @@ protected:
     size_t sum = 1;
     for (size_t count = 0; count < pass_count; count++) {
       folly::rcu_reader g;
-      auto *data = rcu_data.load(std::memory_order_relaxed);
+      auto *data = rcu_data.load(std::memory_order_consume);
       sum += (data->d1 + data->d2);
     }
     EXPECT_EQ(sum, 1);
@@ -56,16 +56,16 @@ protected:
       for (size_t count = 0; count < pass_count; count++) {
         for (int i = 0; i < 100; ++i) {
           if (i < write_percentage) {
-            auto* old_data = rcu_data.load(std::memory_order_relaxed);
+            auto* old_data = rcu_data.load(std::memory_order_consume);
             auto* new_data = new RcuData(*old_data);
             new_data->d1++;
             new_data->d2++;
-            rcu_data.store(new_data, std::memory_order_relaxed);
+            rcu_data.store(new_data, std::memory_order_release);
             folly::synchronize_rcu();
             delete old_data;
           } else {
             folly::rcu_reader g;
-            auto* data = rcu_data.load(std::memory_order_relaxed);
+            auto* data = rcu_data.load(std::memory_order_consume);
             sum += (data->d1 + data->d2);
           }
         }
@@ -80,15 +80,15 @@ protected:
       for (size_t count = 0; count < pass_count; count++) {
         for (int i = 0; i < 100; ++i) {
           if (i < write_percentage) {
-            auto* old_data = rcu_data.load(std::memory_order_relaxed);
+            auto* old_data = rcu_data.load(std::memory_order_consume);
             auto* new_data = new RcuData(*old_data);
             new_data->d1++;
             new_data->d2++;
-            rcu_data.store(new_data, std::memory_order_relaxed);
+            rcu_data.store(new_data, std::memory_order_release);
             folly::rcu_retire(old_data);
           } else {
             folly::rcu_reader g;
-            auto* data = rcu_data.load(std::memory_order_relaxed);
+            auto* data = rcu_data.load(std::memory_order_consume);
             sum += (data->d1 + data->d2);
           }
         }