Skip to content

Commit

Permalink
Report an error even without NDEBUG=1 if a ConcurrentMap becomes full
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Nov 2, 2024
1 parent 85be067 commit baf4f76
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,14 @@ class ConcurrentMap {
#endif
}

std::pair<T *, bool> insert(std::string_view key, u32 hash, const T &val) {
std::pair<T *, bool> insert(std::string_view key, u64 hash, const T &val) {
assert(has_single_bit(nbuckets));

i64 begin = hash & (nbuckets - 1);
u64 begin = hash & (nbuckets - 1);
u64 mask = nbuckets / NUM_SHARDS - 1;

for (i64 i = 0; i < MAX_RETRY; i++) {
i64 idx = (begin & ~mask) | ((begin + i) & mask);
u64 idx = (begin & ~mask) | ((begin + i) & mask);
Entry &ent = entries[idx];

// It seems avoiding compare-and-swap is faster overall at least
Expand Down Expand Up @@ -640,8 +640,8 @@ class ConcurrentMap {
return {&ent.value, false};
}

assert(false && "ConcurrentMap is full");
return {nullptr, false};
std::cerr << "ConcurrentMap is full\n";
abort();
}

i64 get_idx(T *value) const {
Expand Down Expand Up @@ -704,7 +704,7 @@ class ConcurrentMap {
static constexpr i64 MAX_RETRY = 128;

Entry *entries = nullptr;
i64 nbuckets = 0;
u64 nbuckets = 0;
};

//
Expand Down

0 comments on commit baf4f76

Please sign in to comment.