Skip to content

Commit

Permalink
Make CollectionParent::generate_key() threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed May 15, 2023
1 parent 69814d7 commit 1731af1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/realm/collection_parent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ CollectionBasePtr CollectionParent::get_collection_ptr(ColKey col_key) const
int64_t CollectionParent::generate_key(size_t sz) const
{
static std::mt19937 gen32;
static std::mutex mutex;

int64_t key;
const std::lock_guard<std::mutex> lock(mutex);
do {
if (sz < 0x10) {
key = int8_t(gen32());
Expand Down

0 comments on commit 1731af1

Please sign in to comment.