]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: use transparent comparator
authorKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 02:47:20 +0000 (10:47 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 02:48:55 +0000 (10:48 +0800)
for better readability

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

index a69ea8d728af614d1062a8e57fba13a7d693b6de..789d0fd346b954fad50dabff7b8fe70f4f1b5bcb 100644 (file)
@@ -18,13 +18,6 @@ namespace {
 
 namespace crimson::osd {
 
-bool Watch::NotifyCmp::operator()(NotifyRef lhs, NotifyRef rhs) const
-{
-  ceph_assert(lhs);
-  ceph_assert(rhs);
-  return lhs->get_id() < rhs->get_id();
-}
-
 seastar::future<> Watch::connect(crimson::net::ConnectionRef conn, bool)
 {
   if (this->conn == conn) {
@@ -110,11 +103,7 @@ seastar::future<> Watch::remove(const bool send_disconnect)
 void Watch::cancel_notify(const uint64_t notify_id)
 {
   logger().info("{} notify_id={}", __func__, notify_id);
-  const auto it = std::find_if(
-    std::begin(in_progress_notifies), std::end(in_progress_notifies),
-    [notify_id] (const auto& notify) {
-      return notify->ninfo.notify_id == notify_id;
-    });
+  const auto it = in_progress_notifies.find(notify_id);
   assert(it != std::end(in_progress_notifies));
   in_progress_notifies.erase(it);
 }
index f787b34e299e077abf132c0316eaf9facbf3e2de..3632f427280c9246cf9f4365d24a9060a998d75a 100644 (file)
@@ -32,10 +32,7 @@ class Watch : public seastar::enable_shared_from_this<Watch> {
   // used by create().
   struct private_ctag_t{};
 
-  struct NotifyCmp {
-    inline bool operator()(NotifyRef lhs, NotifyRef rhs) const;
-  };
-  std::set<NotifyRef, NotifyCmp> in_progress_notifies;
+  std::set<NotifyRef, std::less<>> in_progress_notifies;
   crimson::net::ConnectionRef conn;
   crimson::osd::ObjectContextRef obc;
 
@@ -145,6 +142,21 @@ class Notify {
   // used by create_n_propagate factory.
   struct private_ctag_t{};
 
+  using ptr_t = seastar::shared_ptr<Notify>;
+  friend bool operator<(const ptr_t& lhs, const ptr_t& rhs) {
+    assert(lhs);
+    assert(rhs);
+    return lhs->get_id() < rhs->get_id();
+  }
+  friend bool operator<(const ptr_t& ptr, const uint64_t id) {
+    assert(ptr);
+    return ptr->get_id() < id;
+  }
+  friend bool operator<(const uint64_t id, const ptr_t& ptr) {
+    assert(ptr);
+    return id < ptr->get_id();
+  }
+
   friend Watch;
 
 public: