]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
shared_cache::add: do not delete value if existed
authorSamuel Just <sam.just@inktank.com>
Wed, 22 Oct 2014 19:40:14 +0000 (12:40 -0700)
committerSamuel Just <sam.just@inktank.com>
Wed, 22 Oct 2014 19:40:14 +0000 (12:40 -0700)
The method contract specifies that we do not want to delete
value if we are not inserting it, so do not initialize val
at the top of the function to take over value.  No current
users appear to trip over this problem (FDCache and
map_cache).

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/shared_cache.hpp

index a5079ede6a0ca096385a66edd211683c987fd5c3..0c4832c51647ccf7ec2ecde6b9788fca960ae9cf 100644 (file)
@@ -209,7 +209,7 @@ public:
    * @return A reference to the map's value for the given key
    */
   VPtr add(const K& key, V *value, bool *existed = NULL) {
-    VPtr val(value, Cleanup(this, key));
+    VPtr val;
     list<VPtr> to_release;
     {
       Mutex::Locker l(lock);
@@ -224,6 +224,7 @@ public:
       if (existed)      
         *existed = false;
 
+      val = VPtr(value, Cleanup(this, key));
       weak_refs.insert(actual, make_pair(key, val));
       lru_add(key, val, &to_release);
     }