diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc index 4dde65ffe09..526e6917db3 100644 --- a/src/rgw/rgw_cache.cc +++ b/src/rgw/rgw_cache.cc @@ -7,6 +7,8 @@ using namespace std; int ObjectCache::get(string& name, ObjectCacheInfo& info, uint32_t mask) { + Mutex::Locker l(lock); + map::iterator iter = cache_map.find(name); if (iter == cache_map.end()) { RGW_LOG(10) << "cache get: name=" << name << " : miss" << dendl; @@ -29,6 +31,8 @@ int ObjectCache::get(string& name, ObjectCacheInfo& info, uint32_t mask) void ObjectCache::put(string& name, ObjectCacheInfo& info) { + Mutex::Locker l(lock); + RGW_LOG(10) << "cache put: name=" << name << dendl; map::iterator iter = cache_map.find(name); if (iter == cache_map.end()) { @@ -67,6 +71,8 @@ void ObjectCache::put(string& name, ObjectCacheInfo& info) void ObjectCache::remove(string& name) { + Mutex::Locker l(lock); + map::iterator iter = cache_map.find(name); if (iter == cache_map.end()) return; diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 9bd8af9cfc9..f3924266f25 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -104,11 +104,12 @@ struct ObjectCacheEntry { class ObjectCache { std::map cache_map; std::list lru; + Mutex lock; void touch_lru(string& name, std::list::iterator& lru_iter); void remove_lru(string& name, std::list::iterator& lru_iter); public: - ObjectCache() { } + ObjectCache() : lock("ObjectCache") { } int get(std::string& name, ObjectCacheInfo& bl, uint32_t mask); void put(std::string& name, ObjectCacheInfo& bl); void remove(std::string& name);