Skip to content

Commit

Permalink
Update linkedhashmap to only Rlock when possible (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
dboehm-avalabs authored Apr 13, 2023
1 parent 915fe42 commit fcb668b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions utils/linkedhashmap/linkedhashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (lh *linkedHashmap[K, V]) Put(key K, val V) {
}

func (lh *linkedHashmap[K, V]) Get(key K) (V, bool) {
lh.lock.Lock()
defer lh.lock.Unlock()
lh.lock.RLock()
defer lh.lock.RUnlock()

return lh.get(key)
}
Expand All @@ -71,22 +71,22 @@ func (lh *linkedHashmap[K, V]) Delete(key K) {
}

func (lh *linkedHashmap[K, V]) Len() int {
lh.lock.Lock()
defer lh.lock.Unlock()
lh.lock.RLock()
defer lh.lock.RUnlock()

return lh.len()
}

func (lh *linkedHashmap[K, V]) Oldest() (K, V, bool) {
lh.lock.Lock()
defer lh.lock.Unlock()
lh.lock.RLock()
defer lh.lock.RUnlock()

return lh.oldest()
}

func (lh *linkedHashmap[K, V]) Newest() (K, V, bool) {
lh.lock.Lock()
defer lh.lock.Unlock()
lh.lock.RLock()
defer lh.lock.RUnlock()

return lh.newest()
}
Expand Down

0 comments on commit fcb668b

Please sign in to comment.