Skip to content
Snippets Groups Projects
Commit 83fcadf2 authored by muXxer's avatar muXxer
Browse files

Fixes deadlocks in LRU cache

parent 383198c0
Branches
Tags
No related merge requests found
......@@ -168,9 +168,9 @@ func (cache *LRUCache) Contains(key interface{}) (result bool) {
keyMutex.RLock()
cache.mutex.RLock()
if element, exists := cache.directory[key]; exists {
cache.mutex.RUnlock()
keyMutex.RUnlock()
cache.mutex.RUnlock()
cache.mutex.Lock()
cache.promoteElement(element)
cache.mutex.Unlock()
......@@ -201,11 +201,11 @@ func (cache *LRUCache) Get(key interface{}) (result interface{}) {
result = element.GetValue().(*lruCacheElement).value
keyMutex.RUnlock()
} else {
cache.mutex.RUnlock()
}
keyMutex.RUnlock()
cache.krwMutex.Free(key)
return
......@@ -243,6 +243,7 @@ func (cache *LRUCache) Delete(key interface{}) bool {
delete(cache.directory, key)
cache.size--
keyMutex.Unlock()
if cache.options.EvictionCallback != nil {
cache.options.EvictionCallback(key, entry.GetValue().(*lruCacheElement).key)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment