]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/simple_cache: Mutex -> ceph::mutex
authorSage Weil <sage@redhat.com>
Tue, 6 Nov 2018 14:46:30 +0000 (08:46 -0600)
committerKefu Chai <kchai@redhat.com>
Wed, 21 Nov 2018 03:56:33 +0000 (11:56 +0800)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/simple_cache.hpp

index 4006576d00bd5184fdf2f24da799b07830044091..77905e929ef17d927e0911c8448a7f7804d99758 100644 (file)
 #ifndef CEPH_SIMPLECACHE_H
 #define CEPH_SIMPLECACHE_H
 
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "include/unordered_map.h"
 
 template <class K, class V, class C = std::less<K>, class H = std::hash<K> >
 class SimpleLRU {
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("SimpleLRU::lock");
   size_t max_size;
   ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H> contents;
   list<pair<K, V> > lru;
@@ -40,17 +40,17 @@ class SimpleLRU {
   }
 
 public:
-  SimpleLRU(size_t max_size) : lock("SimpleLRU::lock"), max_size(max_size) {
+  SimpleLRU(size_t max_size) : max_size(max_size) {
     contents.rehash(max_size);
   }
 
   void pin(K key, V val) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     pinned.emplace(std::move(key), std::move(val));
   }
 
   void clear_pinned(K e) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     for (typename map<K, V, C>::iterator i = pinned.begin();
         i != pinned.end() && i->first <= e;
         pinned.erase(i++)) {
@@ -64,7 +64,7 @@ public:
   }
 
   void clear(K key) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     typename ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H>::iterator i =
       contents.find(key);
     if (i == contents.end())
@@ -74,13 +74,13 @@ public:
   }
 
   void set_size(size_t new_size) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     max_size = new_size;
     trim_cache();
   }
 
   bool lookup(K key, V *out) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     typename ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H>::iterator i =
       contents.find(key);
     if (i != contents.end()) {
@@ -97,7 +97,7 @@ public:
   }
 
   void add(K key, V value) {
-    Mutex::Locker l(lock);
+    std::lock_guard l(lock);
     _add(std::move(key), std::move(value));
   }
 };