Commit d211a58c authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Timed reclamation

Summary:
Continued reclamation issues from lots of UnboundedQueue batches, or lots of threads.

In addition to the current number of outstanding objects, cleanup *all threads* on a timer
basis.

Reviewed By: magedm

Differential Revision: D7429494

fbshipit-source-id: 7e9bdae9ae49927ca0b6e3f24963a4d4b23a4f0b
parent a8e02287
...@@ -242,6 +242,7 @@ class hazptr_priv { ...@@ -242,6 +242,7 @@ class hazptr_priv {
} }
rcount_ = 0; rcount_ = 0;
domain.tryBulkReclaim(); domain.tryBulkReclaim();
domain.tryTimedCleanup();
} }
void collect(hazptr_obj*& colHead, hazptr_obj*& colTail) { void collect(hazptr_obj*& colHead, hazptr_obj*& colTail) {
...@@ -891,6 +892,19 @@ inline hazptr_domain::~hazptr_domain() { ...@@ -891,6 +892,19 @@ inline hazptr_domain::~hazptr_domain() {
} }
} }
inline void hazptr_domain::tryTimedCleanup() {
uint64_t time = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
auto prevtime = syncTime_.load(std::memory_order_relaxed);
if (time < prevtime ||
!syncTime_.compare_exchange_strong(
prevtime, time + syncTimePeriod_, std::memory_order_relaxed)) {
return;
}
cleanup();
}
inline void hazptr_domain::cleanup() { inline void hazptr_domain::cleanup() {
hazptr_obj* h = nullptr; hazptr_obj* h = nullptr;
hazptr_obj* t = nullptr; hazptr_obj* t = nullptr;
......
...@@ -64,6 +64,9 @@ class hazptr_domain { ...@@ -64,6 +64,9 @@ class hazptr_domain {
std::atomic<int> hcount_ = {0}; std::atomic<int> hcount_ = {0};
std::atomic<int> rcount_ = {0}; std::atomic<int> rcount_ = {0};
static constexpr uint64_t syncTimePeriod_{2000000000}; // in ns
std::atomic<uint64_t> syncTime_{0};
public: public:
constexpr explicit hazptr_domain( constexpr explicit hazptr_domain(
memory_resource* = get_default_resource()) noexcept; memory_resource* = get_default_resource()) noexcept;
...@@ -78,6 +81,7 @@ class hazptr_domain { ...@@ -78,6 +81,7 @@ class hazptr_domain {
template <typename T, typename D = std::default_delete<T>> template <typename T, typename D = std::default_delete<T>>
void retire(T* obj, D reclaim = {}); void retire(T* obj, D reclaim = {});
void cleanup(); void cleanup();
void tryTimedCleanup();
private: private:
friend class hazptr_obj_batch; friend class hazptr_obj_batch;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment