Skip to content

Commit

Permalink
Return actual iterator on assign_if_equal
Browse files Browse the repository at this point in the history
Summary: There is no sense to return the iterator that points to the outdated node that just was overwritten by `assign_if_equal` call.

Reviewed By: yfeldblum

Differential Revision: D27678357

fbshipit-source-id: f07ce21df6556819f7eb103a623d3f7a46e72072
  • Loading branch information
Skory authored and facebook-github-bot committed Apr 12, 2021
1 parent c63e060 commit 656319d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions folly/concurrency/detail/ConcurrentHashMap-detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ class alignas(64) BucketTable {
next->acquire_link(); // defined in hazptr_obj_base_linked
}
prev->store(cur, std::memory_order_release);
it.setNode(cur, buckets, bcount, idx);
g.unlock();
// Release not under lock.
node->release();
Expand Down
4 changes: 3 additions & 1 deletion folly/concurrency/test/ConcurrentHashMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,9 @@ TYPED_TEST_P(ConcurrentHashMapTest, HeterogeneousInsert) {

map.insert("foo", "baz");
EXPECT_TRUE(map.assign(foo, "hello2"));
EXPECT_TRUE(map.assign_if_equal("foo", "hello2", "hello"));
auto mbIt = map.assign_if_equal("foo", "hello2", "hello");
EXPECT_TRUE(mbIt);
EXPECT_EQ(mbIt.value()->second, "hello");
EXPECT_EQ(map[foo], "hello");
auto it = map.find(foo);
map.erase(it);
Expand Down

0 comments on commit 656319d

Please sign in to comment.