summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-02-18 14:57:13 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-02-18 14:57:13 +0000
commit4d353d64999d131a7d5cdc831777666ac31c2057 (patch)
tree57acb66fa8fe2af0295214254fc7566123e2dfc0
parentf21e73ccb973968da652e4a93fe8c0d4f031a5c7 (diff)
Form a full release/acquire pair on lock-free hash map shards
When doing a lock-free read of the underlying `_map` we must form an acquire pair with the release done in `ShardedHashMap::alloc_shard` to ensure we observe all transitive writes within the map shard itself.
-rw-r--r--vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp
index 019b98a53dd..2ae22084472 100644
--- a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp
@@ -88,7 +88,7 @@ ShardedHashMap::KvType*
ShardedHashMap::find(const EntryComparator& comp, EntryRef key_ref)
{
ShardedHashComparator shardedComp(comp, key_ref, num_shards);
- auto map = _maps[shardedComp.shard_idx()].load(std::memory_order_relaxed);
+ auto map = _maps[shardedComp.shard_idx()].load(std::memory_order_acquire);
if (map == nullptr) {
return nullptr;
}
@@ -99,7 +99,7 @@ const ShardedHashMap::KvType*
ShardedHashMap::find(const EntryComparator& comp, EntryRef key_ref) const
{
ShardedHashComparator shardedComp(comp, key_ref, num_shards);
- auto map = _maps[shardedComp.shard_idx()].load(std::memory_order_relaxed);
+ auto map = _maps[shardedComp.shard_idx()].load(std::memory_order_acquire);
if (map == nullptr) {
return nullptr;
}
@@ -135,7 +135,7 @@ ShardedHashMap::size() const noexcept
{
size_t result = 0;
for (size_t i = 0; i < num_shards; ++i) {
- auto map = _maps[i].load(std::memory_order_relaxed);
+ auto map = _maps[i].load(std::memory_order_acquire);
if (map != nullptr) {
result += map->size();
}
@@ -148,7 +148,7 @@ ShardedHashMap::get_memory_usage() const
{
MemoryUsage memory_usage(sizeof(ShardedHashMap), sizeof(ShardedHashMap), 0, 0);
for (size_t i = 0; i < num_shards; ++i) {
- auto map = _maps[i].load(std::memory_order_relaxed);
+ auto map = _maps[i].load(std::memory_order_acquire);
if (map != nullptr) {
memory_usage.merge(map->get_memory_usage());
}
@@ -163,7 +163,7 @@ void
ShardedHashMap::foreach_key(std::function<void(EntryRef)> callback) const
{
for (size_t i = 0; i < num_shards; ++i) {
- auto map = _maps[i].load(std::memory_order_relaxed);
+ auto map = _maps[i].load(std::memory_order_acquire);
if (map != nullptr) {
map->foreach_key(callback);
}
@@ -211,7 +211,7 @@ void
ShardedHashMap::foreach_value(std::function<void(const std::vector<EntryRef>&)> callback, const EntryRefFilter& filter)
{
for (size_t i = 0; i < num_shards; ++i) {
- auto map = _maps[i].load(std::memory_order_relaxed);
+ auto map = _maps[i].load(std::memory_order_acquire);
if (map != nullptr) {
map->foreach_value(callback, filter);
}