]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: avoid pthread_mutex_unlock twice 45465/head
authorDai Zhiwei <daizhiwei3@huawei.com>
Mon, 18 Oct 2021 03:34:50 +0000 (11:34 +0800)
committerCory Snyder <csnyder@iland.com>
Wed, 16 Mar 2022 18:53:37 +0000 (14:53 -0400)
        modified:   src/common/cohort_lru.h

Signed-off-by: Dai Zhiwei <daizhiwei3@huawei.com>
(cherry picked from commit a5523129590c4ecf900161f89521b07b73aef615)

src/common/cohort_lru.h

index 2383fc95d7a3b48307896e6b720b11de0f45f472..b105c80ccd5376dca4a62f0958b45136968ae71c 100644 (file)
@@ -139,15 +139,15 @@ namespace cohort {
        for (int ix = 0; ix < n_lanes; ++ix,
               lane_ix = next_evict_lane()) {
          Lane& lane = qlane[lane_ix];
-         lane.lock.lock();
+         std::unique_lock lane_lock{lane.lock};
          /* if object at LRU has refcnt==1, it may be reclaimable */
          Object* o = &(lane.q.back());
          if (can_reclaim(o)) {
            ++(o->lru_refcnt);
            o->lru_flags |= FLAG_EVICTING;
-           lane.lock.unlock();
+           lane_lock.unlock();
            if (o->reclaim(newobj_fac)) {
-             lane.lock.lock();
+             lane_lock.lock();
              --(o->lru_refcnt);
              /* assertions that o state has not changed across
               * relock */
@@ -156,16 +156,13 @@ namespace cohort {
              Object::Queue::iterator it =
                Object::Queue::s_iterator_to(*o);
              lane.q.erase(it);
-             lane.lock.unlock();
              return o;
            } else {
-             // XXX can't make unreachable (means what?)
              --(o->lru_refcnt);
              o->lru_flags &= ~FLAG_EVICTING;
              /* unlock in next block */
            }
          } /* can_reclaim(o) */
-         lane.lock.unlock();
        } /* each lane */
        return nullptr;
       } /* evict_block */