Skip to content

Commit

Permalink
LRUCache tweak - make mutex mutable, allowing const functions
Browse files Browse the repository at this point in the history
- Note: this is common practice, mutexes alone don't change state of the object on lock
  • Loading branch information
astibal committed Apr 20, 2024
1 parent 955be2a commit 47ea9f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/lru.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class LRUCache {
std::unordered_map<Key, std::pair<Value, typename std::list<Key>::iterator>> cache_;
std::list<Key> lruList;

std::mutex lock_;
mutable std::mutex lock_;
public:
explicit LRUCache(size_t cap) : capacity_(cap) {}
std::mutex& lock() { return lock_; }
std::mutex& lock() const { return lock_; }

auto const& get_map_ul() {
auto const& get_map_ul() const {
return cache_;
}

Expand Down

0 comments on commit 47ea9f0

Please sign in to comment.