From: Sage Weil Date: Tue, 6 Nov 2018 14:48:09 +0000 (-0600) Subject: common/shardptr_registry: Mutex -> ceph::mutex X-Git-Tag: v14.1.0~820^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=937dcf030f6fc072b2322fef79fc7151022fa89f;p=ceph.git common/shardptr_registry: Mutex -> ceph::mutex Signed-off-by: Sage Weil --- diff --git a/src/common/map_cacher.hpp b/src/common/map_cacher.hpp index b749460e21dd..e95edfb5c745 100644 --- a/src/common/map_cacher.hpp +++ b/src/common/map_cacher.hpp @@ -15,6 +15,7 @@ #ifndef MAPCACHER_H #define MAPCACHER_H +#include "include/Context.h" #include "common/sharedptr_registry.hpp" namespace MapCacher { diff --git a/src/common/sharedptr_registry.hpp b/src/common/sharedptr_registry.hpp index df9123ff3758..3b3cf01bb28a 100644 --- a/src/common/sharedptr_registry.hpp +++ b/src/common/sharedptr_registry.hpp @@ -17,8 +17,7 @@ #include #include -#include "common/Mutex.h" -#include "common/Cond.h" +#include "common/ceph_mutex.h" /** * Provides a registry of shared_ptr indexed by K while @@ -31,9 +30,9 @@ public: typedef std::weak_ptr WeakVPtr; int waiting; private: - Mutex lock; - Cond cond; - map, C> contents; + ceph::mutex lock = ceph::make_mutex("SharedPtrRegistry::lock"); + ceph::condition_variable cond; + std::map, C> contents; class OnRemoval { SharedPtrRegistry *parent; @@ -43,13 +42,13 @@ private: parent(parent), key(key) {} void operator()(V *to_remove) { { - Mutex::Locker l(parent->lock); - typename map, C>::iterator i = + std::lock_guard l(parent->lock); + typename std::map, C>::iterator i = parent->contents.find(key); if (i != parent->contents.end() && i->second.second == to_remove) { parent->contents.erase(i); - parent->cond.Signal(); + parent->cond.notify_all(); } } delete to_remove; @@ -59,21 +58,20 @@ private: public: SharedPtrRegistry() : - waiting(0), - lock("SharedPtrRegistry::lock") + waiting(0) {} bool empty() { - Mutex::Locker l(lock); + std::lock_guard l(lock); return contents.empty(); } - bool get_next(const K &key, pair *next) { - pair r; + bool get_next(const K &key, std::pair *next) { + std::pair r; { - Mutex::Locker l(lock); + std::lock_guard l(lock); VPtr next_val; - typename map, C>::iterator i = + typename std::map, C>::iterator i = contents.upper_bound(key); while (i != contents.end() && !(next_val = i->second.first.lock())) @@ -81,7 +79,7 @@ public: if (i == contents.end()) return false; if (next) - r = make_pair(i->first, next_val); + r = std::make_pair(i->first, next_val); } if (next) *next = r; @@ -89,10 +87,10 @@ public: } - bool get_next(const K &key, pair *next) { + bool get_next(const K &key, std::pair *next) { VPtr next_val; - Mutex::Locker l(lock); - typename map, C>::iterator i = + std::lock_guard l(lock); + typename std::map, C>::iterator i = contents.upper_bound(key); while (i != contents.end() && !(next_val = i->second.first.lock())) @@ -100,15 +98,15 @@ public: if (i == contents.end()) return false; if (next) - *next = make_pair(i->first, *next_val); + *next = std::make_pair(i->first, *next_val); return true; } VPtr lookup(const K &key) { - Mutex::Locker l(lock); + std::unique_lock l(lock); waiting++; while (1) { - typename map, C>::iterator i = + typename std::map, C>::iterator i = contents.find(key); if (i != contents.end()) { VPtr retval = i->second.first.lock(); @@ -119,17 +117,17 @@ public: } else { break; } - cond.Wait(lock); + cond.wait(l); } waiting--; return VPtr(); } VPtr lookup_or_create(const K &key) { - Mutex::Locker l(lock); + std::unique_lock l(lock); waiting++; while (1) { - typename map, C>::iterator i = + typename std::map, C>::iterator i = contents.find(key); if (i != contents.end()) { VPtr retval = i->second.first.lock(); @@ -140,32 +138,32 @@ public: } else { break; } - cond.Wait(lock); + cond.wait(l); } V *ptr = new V(); VPtr retval(ptr, OnRemoval(this, key)); - contents.insert(make_pair(key, make_pair(retval, ptr))); + contents.insert(std::make_pair(key, make_pair(retval, ptr))); waiting--; return retval; } unsigned size() { - Mutex::Locker l(lock); + std::lock_guard l(lock); return contents.size(); } void remove(const K &key) { - Mutex::Locker l(lock); + std::lock_guard l(lock); contents.erase(key); - cond.Signal(); + cond.notify_all(); } template VPtr lookup_or_create(const K &key, const A &arg) { - Mutex::Locker l(lock); + std::unique_lock l(lock); waiting++; while (1) { - typename map, C>::iterator i = + typename std::map, C>::iterator i = contents.find(key); if (i != contents.end()) { VPtr retval = i->second.first.lock(); @@ -176,11 +174,11 @@ public: } else { break; } - cond.Wait(lock); + cond.wait(l); } V *ptr = new V(arg); VPtr retval(ptr, OnRemoval(this, key)); - contents.insert(make_pair(key, make_pair(retval, ptr))); + contents.insert(std::make_pair(key, make_pair(retval, ptr))); waiting--; return retval; } diff --git a/src/test/common/test_sharedptr_registry.cc b/src/test/common/test_sharedptr_registry.cc index 67039ba9f142..01d0a8489942 100644 --- a/src/test/common/test_sharedptr_registry.cc +++ b/src/test/common/test_sharedptr_registry.cc @@ -28,7 +28,7 @@ class SharedPtrRegistryTest : public SharedPtrRegistry { public: - Mutex &get_lock() { return lock; } + ceph::mutex &get_lock() { return lock; } map, int*> > &get_contents() { return contents; } @@ -85,7 +85,7 @@ public: if (delay > 0) usleep(delay); { - Mutex::Locker l(registry.get_lock()); + std::lock_guard l(registry.get_lock()); if (registry.waiting == waiting) break; } diff --git a/src/test/test_snap_mapper.cc b/src/test/test_snap_mapper.cc index 60d15edf346b..f7224cbdb116 100644 --- a/src/test/test_snap_mapper.cc +++ b/src/test/test_snap_mapper.cc @@ -8,6 +8,7 @@ #include "include/buffer.h" #include "common/map_cacher.hpp" #include "osd/SnapMapper.h" +#include "common/Cond.h" #include "gtest/gtest.h"