From 018eaecc5b91400e4c139b1bef122f858bcd5fc4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 15 Aug 2018 22:22:23 +0800 Subject: [PATCH] common/shared_cache: add `std::` we cannot assume `using namespace std`, and the build actually fails without this change. Signed-off-by: Kefu Chai --- src/common/shared_cache.hpp | 41 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index 1375e4e57a955..af58eb1a5453a 100644 --- a/src/common/shared_cache.hpp +++ b/src/common/shared_cache.hpp @@ -17,6 +17,7 @@ #include #include +#include "common/dout.h" #include "common/lock_cond.h" #include "common/lock_mutex.h" #include "common/lock_policy.h" @@ -42,12 +43,12 @@ public: private: using C = std::less; using H = std::hash; - ceph::unordered_map >::iterator, H> contents; - list > lru; + ceph::unordered_map >::iterator, H> contents; + std::list > lru; - map, C> weak_refs; + std::map, C> weak_refs; - void trim_cache(list *to_release) { + void trim_cache(std::list *to_release) { while (size > max_size) { to_release->push_back(lru.back().second); lru_remove(lru.back().first); @@ -55,8 +56,7 @@ private: } void lru_remove(const K& key) { - typename ceph::unordered_map >::iterator, H>::iterator i = - contents.find(key); + auto i = contents.find(key); if (i == contents.end()) return; lru.erase(i->second); @@ -64,9 +64,8 @@ private: contents.erase(i); } - void lru_add(const K& key, const VPtr& val, list *to_release) { - typename ceph::unordered_map >::iterator, H>::iterator i = - contents.find(key); + void lru_add(const K& key, const VPtr& val, std::list *to_release) { + auto i = contents.find(key); if (i != contents.end()) { lru.splice(lru.begin(), lru, i->second); } else { @@ -79,7 +78,7 @@ private: void remove(const K& key, V *valptr) { std::lock_guard l{lock}; - typename map, 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); } @@ -147,13 +146,11 @@ public: *_dout << dendl; } - void dump_weak_refs(ostream& out) { - for (typename map, 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; } } @@ -236,12 +233,12 @@ public: } return val; } - bool get_next(const K &key, pair *next) { - pair r; + bool get_next(const K &key, std::pair *next) { + std::pair r; { std::lock_guard l{lock}; VPtr next_val; - typename map, C>::iterator i = weak_refs.upper_bound(key); + typename std::map, C>::iterator i = weak_refs.upper_bound(key); while (i != weak_refs.end() && !(next_val = i->second.first.lock())) @@ -257,8 +254,8 @@ public: *next = r; return true; } - bool get_next(const K &key, pair *next) { - pair r; + bool get_next(const K &key, std::pair *next) { + std::pair r; bool found = get_next(key, &r); if (!found || !next) return found; @@ -270,7 +267,7 @@ public: VPtr lookup(const K& key) { VPtr val; - list to_release; + std::list to_release; { std::unique_lock l{lock}; ++waiting; -- 2.39.5