#include <map>
#include <list>
+#include "common/dout.h"
#include "common/lock_cond.h"
#include "common/lock_mutex.h"
#include "common/lock_policy.h"
private:
using C = std::less<K>;
using H = std::hash<K>;
- ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H> contents;
- list<pair<K, VPtr> > lru;
+ ceph::unordered_map<K, typename std::list<std::pair<K, VPtr> >::iterator, H> contents;
+ std::list<std::pair<K, VPtr> > lru;
- map<K, pair<WeakVPtr, V*>, C> weak_refs;
+ std::map<K, std::pair<WeakVPtr, V*>, C> weak_refs;
- void trim_cache(list<VPtr> *to_release) {
+ void trim_cache(std::list<VPtr> *to_release) {
while (size > max_size) {
to_release->push_back(lru.back().second);
lru_remove(lru.back().first);
}
void lru_remove(const K& key) {
- typename ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H>::iterator i =
- contents.find(key);
+ auto i = contents.find(key);
if (i == contents.end())
return;
lru.erase(i->second);
contents.erase(i);
}
- void lru_add(const K& key, const VPtr& val, list<VPtr> *to_release) {
- typename ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H>::iterator i =
- contents.find(key);
+ void lru_add(const K& key, const VPtr& val, std::list<VPtr> *to_release) {
+ auto i = contents.find(key);
if (i != contents.end()) {
lru.splice(lru.begin(), lru, i->second);
} else {
void remove(const K& key, V *valptr) {
std::lock_guard l{lock};
- typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.find(key);
+ auto i = weak_refs.find(key);
if (i != weak_refs.end() && i->second.second == valptr) {
weak_refs.erase(i);
}
*_dout << dendl;
}
- void dump_weak_refs(ostream& out) {
- for (typename map<K, pair<WeakVPtr, V*>, C>::iterator p = weak_refs.begin();
- p != weak_refs.end();
- ++p) {
+ void dump_weak_refs(std::ostream& out) {
+ for (const auto& [key, ref] : weak_refs) {
out << __func__ << " " << this << " weak_refs: "
- << p->first << " = " << p->second.second
- << " with " << p->second.first.use_count() << " refs"
+ << key << " = " << ref.second
+ << " with " << ref.first.use_count() << " refs"
<< std::endl;
}
}
}
return val;
}
- bool get_next(const K &key, pair<K, VPtr> *next) {
- pair<K, VPtr> r;
+ bool get_next(const K &key, std::pair<K, VPtr> *next) {
+ std::pair<K, VPtr> r;
{
std::lock_guard l{lock};
VPtr next_val;
- typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.upper_bound(key);
+ typename std::map<K, std::pair<WeakVPtr, V*>, C>::iterator i = weak_refs.upper_bound(key);
while (i != weak_refs.end() &&
!(next_val = i->second.first.lock()))
*next = r;
return true;
}
- bool get_next(const K &key, pair<K, V> *next) {
- pair<K, VPtr> r;
+ bool get_next(const K &key, std::pair<K, V> *next) {
+ std::pair<K, VPtr> r;
bool found = get_next(key, &r);
if (!found || !next)
return found;
VPtr lookup(const K& key) {
VPtr val;
- list<VPtr> to_release;
+ std::list<VPtr> to_release;
{
std::unique_lock l{lock};
++waiting;