]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/shared_cache: add `std::`
authorKefu Chai <kchai@redhat.com>
Wed, 15 Aug 2018 14:22:23 +0000 (22:22 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 16 Aug 2018 09:33:48 +0000 (17:33 +0800)
we cannot assume `using namespace std`, and the build actually fails
without this change.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/shared_cache.hpp

index 1375e4e57a955092e63ffc7366bee1b9fc7e3b67..af58eb1a5453afac39dc538d3823ac6caed595e8 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <map>
 #include <list>
+#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<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);
@@ -55,8 +56,7 @@ private:
   }
 
   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);
@@ -64,9 +64,8 @@ private:
     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 {
@@ -79,7 +78,7 @@ private:
 
   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);
     }
@@ -147,13 +146,11 @@ public:
     *_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;
     }
   }
@@ -236,12 +233,12 @@ public:
     }
     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()))
@@ -257,8 +254,8 @@ public:
       *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;
@@ -270,7 +267,7 @@ public:
 
   VPtr lookup(const K& key) {
     VPtr val;
-    list<VPtr> to_release;
+    std::list<VPtr> to_release;
     {
       std::unique_lock l{lock};
       ++waiting;