Add threshold for thread local retired objects
[folly.git] / folly / experimental / hazptr / hazptr-impl.h
index 823f2ebf68aa3a2781de014404e3f8762d590388..5c343c5c7a6dc1058a0403f49131e611deb968c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 /* override-include-guard */
 #ifndef HAZPTR_H
 #error "This should only be included by hazptr.h"
 /* override-include-guard */
 #ifndef HAZPTR_H
 #error "This should only be included by hazptr.h"
 #define HAZPTR_PRIV true
 #endif
 
 #define HAZPTR_PRIV true
 #endif
 
+#ifndef HAZPTR_PRIV_THRESHOLD
+#define HAZPTR_PRIV_THRESHOLD 20
+#endif
+
 #ifndef HAZPTR_ONE_DOMAIN
 #define HAZPTR_ONE_DOMAIN false
 #endif
 #ifndef HAZPTR_ONE_DOMAIN
 #define HAZPTR_ONE_DOMAIN false
 #endif
@@ -265,12 +268,11 @@ inline bool hazptr_obj_base_refcounted<T, D>::release_ref() {
  *  hazptr_rec
  */
 
  *  hazptr_rec
  */
 
-class hazptr_rec {
+class alignas(hardware_destructive_interference_size) hazptr_rec {
   friend class hazptr_domain;
   friend class hazptr_holder;
   friend struct hazptr_tc_entry;
 
   friend class hazptr_domain;
   friend class hazptr_holder;
   friend struct hazptr_tc_entry;
 
-  FOLLY_ALIGN_TO_AVOID_FALSE_SHARING
   std::atomic<const void*> hazptr_{nullptr};
   hazptr_rec* next_{nullptr};
   std::atomic<bool> active_{false};
   std::atomic<const void*> hazptr_{nullptr};
   hazptr_rec* next_{nullptr};
   std::atomic<bool> active_{false};
@@ -452,9 +454,10 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array(
     hazptr_array&& other) noexcept {
   DEBUG_PRINT(this << " " << M << " " << &other);
   auto h = reinterpret_cast<hazptr_holder*>(&raw_);
     hazptr_array&& other) noexcept {
   DEBUG_PRINT(this << " " << M << " " << &other);
   auto h = reinterpret_cast<hazptr_holder*>(&raw_);
+  auto hother = reinterpret_cast<hazptr_holder*>(&other.raw_);
   for (size_t i = 0; i < M; ++i) {
   for (size_t i = 0; i < M; ++i) {
-    new (&h[i]) hazptr_holder(std::move(other.h_[i]));
-    DEBUG_PRINT(i << " " << &h[i] << " " << &other.h_[i]);
+    new (&h[i]) hazptr_holder(std::move(hother[i]));
+    DEBUG_PRINT(i << " " << &h[i] << " " << &hother[i]);
   }
   empty_ = other.empty_;
   other.empty_ = true;
   }
   empty_ = other.empty_;
   other.empty_ = true;
@@ -994,8 +997,7 @@ inline void hazptr_priv::push(hazptr_obj* obj) {
     head_ = obj;
   }
   tail_ = obj;
     head_ = obj;
   }
   tail_ = obj;
-  ++rcount_;
-  if (domain.reachedThreshold(rcount_)) {
+  if (++rcount_ >= HAZPTR_PRIV_THRESHOLD) {
     pushAllToDomain();
   }
 }
     pushAllToDomain();
   }
 }