Commit f6cbd144 authored by Andrey Malevich's avatar Andrey Malevich Committed by Facebook Github Bot

Back out "[folly] more ConcurrentHashMap deletion tests"

Summary:
Original commit changeset: bee63b3f597d.

Original revision is breaking integration tests by failing with the SIGSEGV in operator++, please check D6993857 for more details.

Reviewed By: anshulverma

Differential Revision: D7051998

fbshipit-source-id: e5cfbb22aee5f5ec9871a9a34bb27eb5b0036d1b
parent 051bd89d
...@@ -444,17 +444,13 @@ class ConcurrentHashMap { ...@@ -444,17 +444,13 @@ class ConcurrentHashMap {
void next() { void next() {
while (it_ == parent_->ensureSegment(segment_)->cend() && while (it_ == parent_->ensureSegment(segment_)->cend() &&
segment_ < parent_->NumShards) { segment_ < parent_->NumShards) {
SegmentT* seg{nullptr}; segment_++;
while (!seg) { auto seg = parent_->segments_[segment_].load(std::memory_order_acquire);
segment_++; if (segment_ < parent_->NumShards) {
seg = parent_->segments_[segment_].load(std::memory_order_acquire); if (!seg) {
if (segment_ < parent_->NumShards) { continue;
if (!seg) {
continue;
}
it_ = seg->cbegin();
} }
break; it_ = seg->cbegin();
} }
} }
} }
......
...@@ -589,8 +589,6 @@ class alignas(64) ConcurrentHashMapSegment { ...@@ -589,8 +589,6 @@ class alignas(64) ConcurrentHashMapSegment {
// throw if hash or key_eq functions throw. // throw if hash or key_eq functions throw.
void erase(Iterator& res, Iterator& pos) { void erase(Iterator& res, Iterator& pos) {
erase_internal(pos->first, &res); erase_internal(pos->first, &res);
// Invalidate the iterator.
pos = cend();
} }
void clear() { void clear() {
......
...@@ -594,107 +594,25 @@ TEST(ConcurrentHashMap, RefcountTest) { ...@@ -594,107 +594,25 @@ TEST(ConcurrentHashMap, RefcountTest) {
} }
struct Wrapper { struct Wrapper {
explicit Wrapper(bool& del_) : del(del_) {} Wrapper() = default;
~Wrapper() { ~Wrapper() {
del = true; del = true;
} }
bool& del; static bool del;
}; };
TEST(ConcurrentHashMap, Deletion) { bool Wrapper::del = false;
bool del{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del)); TEST(ConcurrentHashMap, Deletion) {
} EXPECT_FALSE(Wrapper::del);
EXPECT_TRUE(del);
}
TEST(ConcurrentHashMap, DeletionWithErase) {
bool del{false};
{ {
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map; ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del)); map.insert(0, std::make_shared<Wrapper>());
map.erase(0); map.erase(0);
} }
EXPECT_TRUE(del); EXPECT_TRUE(Wrapper::del);
}
TEST(ConcurrentHashMap, DeletionWithIterator) {
bool del{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del));
auto it = map.find(0);
map.erase(it);
}
EXPECT_TRUE(del);
}
TEST(ConcurrentHashMap, DeletionWithForLoop) {
bool del{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del));
for (auto it = map.cbegin(); it != map.cend(); ++it) {
EXPECT_EQ(it->first, 0);
}
}
EXPECT_TRUE(del);
}
TEST(ConcurrentHashMap, DeletionMultiple) {
bool del1{false}, del2{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del1));
map.insert(1, std::make_shared<Wrapper>(del2));
}
EXPECT_TRUE(del1);
EXPECT_TRUE(del2);
}
TEST(ConcurrentHashMap, DeletionAssigned) {
bool del1{false}, del2{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map;
map.insert(0, std::make_shared<Wrapper>(del1));
map.insert_or_assign(0, std::make_shared<Wrapper>(del2));
}
EXPECT_TRUE(del1);
EXPECT_TRUE(del2);
}
TEST(ConcurrentHashMap, DeletionMultipleMaps) {
bool del1{false}, del2{false};
{
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map1;
ConcurrentHashMap<int, std::shared_ptr<Wrapper>> map2;
map1.insert(0, std::make_shared<Wrapper>(del1));
map2.insert(0, std::make_shared<Wrapper>(del2));
}
EXPECT_TRUE(del1);
EXPECT_TRUE(del2);
} }
...@@ -702,7 +702,6 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() { ...@@ -702,7 +702,6 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() {
auto count = tc.count(); auto count = tc.count();
if ((M <= HAZPTR_TC_SIZE) && (count + M <= HAZPTR_TC_SIZE)) { if ((M <= HAZPTR_TC_SIZE) && (count + M <= HAZPTR_TC_SIZE)) {
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
h[i].reset();
tc[count + i].hprec_ = h[i].hazptr_; tc[count + i].hprec_ = h[i].hazptr_;
HAZPTR_DEBUG_PRINT(i << " " << &h[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i]);
new (&h[i]) hazptr_holder(nullptr); new (&h[i]) hazptr_holder(nullptr);
......
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