mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
cache: add a method to get estimated cache size
Estimated because there is no lock preventing the result from changing before it is used. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
331cb142e3
commit
ece58cc910
@ -30,7 +30,7 @@ namespace crucible {
|
||||
map<Key, ListIter> m_map;
|
||||
LockSet<Key> m_lockset;
|
||||
size_t m_max_size;
|
||||
mutex m_mutex;
|
||||
mutable mutex m_mutex;
|
||||
|
||||
void check_overflow();
|
||||
void recent_use(ListIter vp);
|
||||
@ -48,6 +48,7 @@ namespace crucible {
|
||||
void expire(Arguments... args);
|
||||
void insert(const Return &r, Arguments... args);
|
||||
void clear();
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <class Return, class... Arguments>
|
||||
@ -190,6 +191,14 @@ namespace crucible {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
template <class Return, class... Arguments>
|
||||
size_t
|
||||
LRUCache<Return, Arguments...>::size() const
|
||||
{
|
||||
unique_lock<mutex> lock(m_mutex);
|
||||
return m_map.size();
|
||||
}
|
||||
|
||||
template<class Return, class... Arguments>
|
||||
Return
|
||||
LRUCache<Return, Arguments...>::operator()(Arguments... args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user