]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: pass function using rvalue reference
authorKefu Chai <kchai@redhat.com>
Thu, 28 Jan 2021 07:23:14 +0000 (15:23 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 28 Jan 2021 12:57:23 +0000 (20:57 +0800)
instead of passing a copy, pass a reference. so we can save the overhead
of copying the function object.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h

index 200a2918c87020d069f5a03eca10341bab8626a9..7cbb09ba5d1f75c95f22aba21b9b9e19ec2dd9ea 100644 (file)
@@ -7699,7 +7699,7 @@ MPGStats* OSD::collect_pg_stats()
     if (!pg->is_primary()) {
       continue;
     }
-    pg->get_pg_stats([&](const pg_stat_t& s, epoch_t lec) {
+    pg->with_pg_stats([&](const pg_stat_t& s, epoch_t lec) {
        m->pg_stat[pg->pg_id.pgid] = s;
        min_last_epoch_clean = std::min(min_last_epoch_clean, lec);
        min_last_epoch_clean_pgs.push_back(pg->pg_id.pgid);
index fef4b65dfcda32cf86f5b832a159e1647b6522c4..69f5f111fc454386e3d9cf61fe893747c36cad96 100644 (file)
@@ -2791,7 +2791,7 @@ void PG::dump_missing(Formatter *f)
   }
 }
 
-void PG::get_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)> f)
+void PG::with_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)>&& f)
 {
   std::lock_guard l{pg_stats_publish_lock};
   if (pg_stats_publish) {
@@ -2799,7 +2799,7 @@ void PG::get_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)> f)
   }
 }
 
-void PG::with_heartbeat_peers(std::function<void(int)> f)
+void PG::with_heartbeat_peers(std::function<void(int)>&& f)
 {
   std::lock_guard l{heartbeat_peer_lock};
   for (auto p : heartbeat_peers) {
index 67a1c80459df6b6d69f81e9eaf1ccdf700ce2b00..37e96b2bf90af82e8c429a99b8245fad38708fd2 100644 (file)
@@ -533,8 +533,8 @@ public:
   void dump_pgstate_history(ceph::Formatter *f);
   void dump_missing(ceph::Formatter *f);
 
-  void get_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)> f);
-  void with_heartbeat_peers(std::function<void(int)> f);
+  void with_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)>&& f);
+  void with_heartbeat_peers(std::function<void(int)>&& f);
 
   void shutdown();
   virtual void on_shutdown() = 0;