From 36be3f79d461a3c60aee79a38e9361ff72ab0cc7 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 19 Sep 2023 11:53:02 -0500 Subject: [PATCH] GH-1639 Favor this over rhs for queue comparison. Also use C++20 spaceship comparison. --- .../include/eosio/chain/exec_pri_queue.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp b/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp index bb0a6b62d4..6321fb8add 100644 --- a/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp +++ b/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp @@ -116,8 +116,9 @@ class exec_pri_queue : public boost::asio::execution_context // true if this queue has the highest priority task to execute std::optional compare_queues_locked( const exec_pri_queue& rhs ) { std::scoped_lock g(mtx_, rhs.mtx_); - if (empty() && rhs.empty()) return {}; - return !empty() && (rhs.empty() || *rhs.top() < *top()); + if (empty() && rhs.empty()) + return {}; + return !empty() && (rhs.empty() || *rhs.top() <= *top()); } class executor @@ -192,14 +193,10 @@ class exec_pri_queue : public boost::asio::execution_context virtual void execute() = 0; int priority() const { return priority_; } - // C++20 - // friend std::weak_ordering operator<=>(const queued_handler_base&, - // const queued_handler_base&) noexcept = default; - friend bool operator<(const queued_handler_base& a, - const queued_handler_base& b) noexcept - { - return std::tie( a.priority_, a.order_ ) < std::tie( b.priority_, b.order_ ); - } + + // comparison eval: (priority_, order_) + friend auto operator<=>(const queued_handler_base& a, + const queued_handler_base& b) noexcept = default; private: int priority_;