Commit f0a3212d authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

ConcurrentHashMap: Try reclaim objects immediately in destructor.

Summary: Destructor unlinks and reclaims nodes immediately without checking hazard pointers.

Reviewed By: djwatson

Differential Revision: D8864161

fbshipit-source-id: 270df5e6b3ef8bc33934b6d55df465309f1068bd
parent dbaf54c0
......@@ -244,7 +244,9 @@ class alignas(64) ConcurrentHashMapSegment {
auto buckets = buckets_.load(std::memory_order_relaxed);
// We can delete and not retire() here, since users must have
// their own synchronization around destruction.
buckets->destroy(bucket_count_.load(std::memory_order_relaxed));
auto count = bucket_count_.load(std::memory_order_relaxed);
buckets->unlink_and_reclaim_nodes(count);
buckets->destroy(count);
}
size_t size() {
......@@ -675,6 +677,23 @@ class alignas(64) ConcurrentHashMapSegment {
(uint8_t*)this, sizeof(BucketRoot) * count + sizeof(*this));
}
void unlink_and_reclaim_nodes(size_t count) {
for (size_t i = 0; i < count; i++) {
auto node = buckets_[i]().load(std::memory_order_relaxed);
if (node) {
buckets_[i]().store(nullptr, std::memory_order_relaxed);
while (node) {
auto next = node->next_.load(std::memory_order_relaxed);
if (next) {
node->next_.store(nullptr, std::memory_order_relaxed);
}
node->unlink_and_reclaim_unchecked();
node = next;
}
}
}
}
BucketRoot buckets_[0];
};
......
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