Skip to content

Commit

Permalink
GH-1639 Favor this over rhs for queue comparison. Also use C++20 spac…
Browse files Browse the repository at this point in the history
…eship comparison.
  • Loading branch information
heifner committed Sep 19, 2023
1 parent 11df9d1 commit 36be3f7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit 36be3f7

Please sign in to comment.