ReadMostlyMainPtrDeleter
[folly.git] / folly / experimental / RCURefCount.h
index 5acda32c65cbaf5e0b4a8abc5d2ee40bb5dc5555..059394c8c1387dd22648b6267b950c84ce14f78b 100644 (file)
@@ -97,17 +97,27 @@ class RCURefCount {
   }
 
   void useGlobal() noexcept {
-    state_ = State::GLOBAL_TRANSITION;
+    std::array<RCURefCount*, 1> ptrs{{this}};
+    useGlobal(ptrs);
+  }
+
+  template <typename Container>
+  static void useGlobal(const Container& refCountPtrs) {
+    for (auto refCountPtr : refCountPtrs) {
+      refCountPtr->state_ = State::GLOBAL_TRANSITION;
+    }
 
     synchronize_rcu();
     // At this point everyone is using the global count
 
-    auto accessor = localCount_.accessAllThreads();
-    for (auto& count : accessor) {
-      count.collect();
-    }
+    for (auto refCountPtr : refCountPtrs) {
+      auto accessor = refCountPtr->localCount_.accessAllThreads();
+      for (auto& count : accessor) {
+        count.collect();
+      }
 
-    state_ = State::GLOBAL;
+      refCountPtr->state_ = State::GLOBAL;
+    }
 
     synchronize_rcu();
     // After this ++ or -- can return 0.