diff --git a/implementations/caching/cache/Cache.h b/implementations/caching/cache/Cache.h index 48655660..04cf14b2 100644 --- a/implementations/caching/cache/Cache.h +++ b/implementations/caching/cache/Cache.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace blockstore { namespace caching { @@ -61,14 +61,12 @@ Cache::~Cache() { template boost::optional Cache::pop(const Key &key) { std::unique_lock lock(_mutex); - _currentlyFlushingEntries.lock(key, &lock); + cpputils::MutexPoolLock lockEntryFromBeingPopped(&_currentlyFlushingEntries, key, &lock); auto found = _cachedBlocks.pop(key); if (!found) { return boost::none; } - - _currentlyFlushingEntries.release(key); return found->releaseValue(); } @@ -96,14 +94,13 @@ template void Cache::_deleteEntry(std::unique_lock *lock) { auto key = _cachedBlocks.peekKey(); ASSERT(key != boost::none, "There was no entry to delete"); - _currentlyFlushingEntries.lock(*key); + cpputils::MutexPoolLock lockEntryFromBeingPopped(&_currentlyFlushingEntries, *key); auto value = _cachedBlocks.pop(); // Call destructor outside of the unique_lock, // i.e. pop() and push() can be called here, except for pop() on the element in _currentlyFlushingEntries lock->unlock(); value = boost::none; // Call destructor lock->lock(); - _currentlyFlushingEntries.release(*key); }; template