From: Casey Bodley Date: Wed, 7 Aug 2019 17:55:03 +0000 (-0400) Subject: rgw: fix unlock of shared lock in RGWDataChangesLog X-Git-Tag: v15.1.0~1933^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=553d97ca959ffd4f1e11848564a286da375175bf;p=ceph-ci.git rgw: fix unlock of shared lock in RGWDataChangesLog std::shared_mutex expects a call to unlock_shared() after lock_shared(). use the std::shared_lock guard to make it more obviously correct Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 369cd80da34..c6a441e9035 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -2486,18 +2486,15 @@ void RGWDataChangesLog::ChangesRenewThread::stop() void RGWDataChangesLog::mark_modified(int shard_id, const rgw_bucket_shard& bs) { auto key = bs.get_key(); - modified_lock.lock_shared(); - map >::iterator iter = modified_shards.find(shard_id); - if (iter != modified_shards.end()) { - set& keys = iter->second; - if (keys.find(key) != keys.end()) { - modified_lock.unlock(); + { + std::shared_lock rl{modified_lock}; // read lock to check for existence + auto shard = modified_shards.find(shard_id); + if (shard != modified_shards.end() && shard->second.count(key)) { return; } } - modified_lock.unlock(); - std::unique_lock wl{modified_lock}; + std::unique_lock wl{modified_lock}; // write lock for insertion modified_shards[shard_id].insert(key); }