From 73101b74ea7d913d198a3cb90d68fb8578010835 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 1 Oct 2015 15:52:43 +0200 Subject: [PATCH] Better locking for cache --- implementations/caching/cache/Cache.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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