Skip to content

Commit

Permalink
Merge pull request #508 from 0xPolygonHermez/rick/fix_associativeCach…
Browse files Browse the repository at this point in the history
…e_race

Added recursive_mutex in associative cache
  • Loading branch information
fractasy authored Aug 21, 2023
2 parents cff8844 + b45acf1 commit 485ce94
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hashdb/database_associative_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DatabaseMTAssociativeCache::~DatabaseMTAssociativeCache()

void DatabaseMTAssociativeCache::postConstruct(int nKeyBits_, int log2CacheSize_, string name_)
{
lock_guard<recursive_mutex> guard(mlock);
nKeyBits = nKeyBits_;
if (nKeyBits_ > 32)
{
Expand Down Expand Up @@ -102,7 +103,7 @@ void DatabaseMTAssociativeCache::postConstruct(int nKeyBits_, int log2CacheSize_

void DatabaseMTAssociativeCache::addKeyValue(Goldilocks::Element (&key)[4], const vector<Goldilocks::Element> &value, bool update)
{

lock_guard<recursive_mutex> guard(mlock);
//
// Statistics
//
Expand Down Expand Up @@ -208,6 +209,11 @@ void DatabaseMTAssociativeCache::addKeyValue(Goldilocks::Element (&key)[4], cons
values[cacheIndexValue + 9] = value[9];
values[cacheIndexValue + 10] = value[10];
values[cacheIndexValue + 11] = value[11];
}else{
values[cacheIndexValue + 8] = Goldilocks::zero();
values[cacheIndexValue + 9] = Goldilocks::zero();
values[cacheIndexValue + 10] = Goldilocks::zero();
values[cacheIndexValue + 11] = Goldilocks::zero();
}
//
// Forced index insertion
Expand Down Expand Up @@ -280,6 +286,7 @@ void DatabaseMTAssociativeCache::forcedInsertion(uint32_t (&rawCacheIndexes)[10]

bool DatabaseMTAssociativeCache::findKey(Goldilocks::Element (&key)[4], vector<Goldilocks::Element> &value)
{
lock_guard<recursive_mutex> guard(mlock);
attempts++;
for (int i = 0; i < 4; i++)
{
Expand Down

0 comments on commit 485ce94

Please sign in to comment.