From: Sage Weil Date: Tue, 6 Nov 2018 14:41:58 +0000 (-0600) Subject: common/random_cache: Mutex -> ceph::mutex X-Git-Tag: v14.1.0~820^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=648ce452b5676cac9a8a27091263e9aab421f3e2;p=ceph-ci.git common/random_cache: Mutex -> ceph::mutex Signed-off-by: Sage Weil --- diff --git a/src/common/random_cache.hpp b/src/common/random_cache.hpp index c6278470643..ad4a5d06a92 100644 --- a/src/common/random_cache.hpp +++ b/src/common/random_cache.hpp @@ -17,7 +17,7 @@ #ifndef CEPH_RANDOMCACHE_H #define CEPH_RANDOMCACHE_H -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "include/compat.h" #include "include/unordered_map.h" @@ -30,7 +30,7 @@ template class RandomCache { // The first element of pair is the frequency of item, it's used to evict item ceph::unordered_map > contents; - Mutex lock; + ceph::mutex lock = ceph::make_mutex("RandomCache::lock"); uint64_t max_size; K last_trim_key; @@ -69,19 +69,18 @@ class RandomCache { } public: - RandomCache(size_t max_size=20) : lock("RandomCache::lock"), - max_size(max_size) {} + RandomCache(size_t max_size=20) : max_size(max_size) {} ~RandomCache() { contents.clear(); } void clear(K key) { - Mutex::Locker l(lock); + std::lock_guard l(lock); contents.erase(key); } void set_size(size_t new_size) { - Mutex::Locker l(lock); + std::lock_guard l(lock); max_size = new_size; if (max_size <= contents.size()) { trim_cache(contents.size() - max_size); @@ -89,7 +88,7 @@ class RandomCache { } bool lookup(K key, V *out) { - Mutex::Locker l(lock); + std::lock_guard l(lock); typename ceph::unordered_map >::iterator it = contents.find(key); if (it != contents.end()) { it->second.first++; @@ -100,7 +99,7 @@ class RandomCache { } void add(K key, V value) { - Mutex::Locker l(lock); + std::lock_guard l(lock); if (max_size <= contents.size()) { trim_cache(EVICT_COUNT); }