diff --git a/nano/core_test/scheduler_buckets.cpp b/nano/core_test/scheduler_buckets.cpp index 0a9c6adfba..913a6601db 100644 --- a/nano/core_test/scheduler_buckets.cpp +++ b/nano/core_test/scheduler_buckets.cpp @@ -110,7 +110,7 @@ TEST (buckets, construction) { nano::scheduler::buckets buckets; ASSERT_EQ (0, buckets.size ()); - ASSERT_TRUE (buckets.empty ()); + ASSERT_TRUE (buckets.empty () && !buckets.available ()); // Initial state ASSERT_EQ (62, buckets.bucket_count ()); } diff --git a/nano/node/scheduler/bucket.cpp b/nano/node/scheduler/bucket.cpp index 51ba1626a5..7583f6604d 100644 --- a/nano/node/scheduler/bucket.cpp +++ b/nano/node/scheduler/bucket.cpp @@ -53,6 +53,11 @@ bool nano::scheduler::bucket::empty () const return queue.empty (); } +bool nano::scheduler::bucket::available () const +{ + return !queue.empty (); +} + void nano::scheduler::bucket::dump () const { for (auto const & item : queue) diff --git a/nano/node/scheduler/bucket.hpp b/nano/node/scheduler/bucket.hpp index 2f32c17d59..0417eb523d 100644 --- a/nano/node/scheduler/bucket.hpp +++ b/nano/node/scheduler/bucket.hpp @@ -34,6 +34,7 @@ class bucket final void push (uint64_t time, std::shared_ptr block); size_t size () const; bool empty () const; + bool available () const; void dump () const; }; } // namespace nano::scheduler diff --git a/nano/node/scheduler/buckets.cpp b/nano/node/scheduler/buckets.cpp index c033f6f6ca..00866afea8 100644 --- a/nano/node/scheduler/buckets.cpp +++ b/nano/node/scheduler/buckets.cpp @@ -19,7 +19,7 @@ void nano::scheduler::buckets::next () void nano::scheduler::buckets::seek () { next (); - for (std::size_t i = 0, n = buckets_m.size (); (*current)->empty () && i < n; ++i) + for (std::size_t i = 0, n = buckets_m.size (); !(*current)->available () && i < n; ++i) { next (); } @@ -73,10 +73,10 @@ std::size_t nano::scheduler::buckets::index (nano::uint128_t const & balance) co */ void nano::scheduler::buckets::push (uint64_t time, std::shared_ptr block, nano::amount const & priority) { - auto was_empty = empty (); + auto was_available = available (); auto & bucket = buckets_m[index (priority.number ())]; bucket->push (time, block); - if (was_empty) + if (!was_available) { seek (); } @@ -85,7 +85,7 @@ void nano::scheduler::buckets::push (uint64_t time, std::shared_ptr /** Return the highest priority block of the current bucket */ std::shared_ptr nano::scheduler::buckets::top () const { - debug_assert (!empty ()); + debug_assert (available ()); auto result = (*current)->top (); return result; } @@ -93,7 +93,7 @@ std::shared_ptr nano::scheduler::buckets::top () const /** Pop the current block from the container and seek to the next block, if it exists */ void nano::scheduler::buckets::pop () { - debug_assert (!empty ()); + debug_assert (available ()); auto & bucket = *current; bucket->pop (); seek (); @@ -128,6 +128,11 @@ bool nano::scheduler::buckets::empty () const return std::all_of (buckets_m.begin (), buckets_m.end (), [] (auto const & bucket) { return bucket->empty (); }); } +bool nano::scheduler::buckets::available () const +{ + return std::any_of (buckets_m.begin (), buckets_m.end (), [] (auto const & bucket) { return bucket->available (); }); +} + /** Print the state of the class in stderr */ void nano::scheduler::buckets::dump () const { diff --git a/nano/node/scheduler/buckets.hpp b/nano/node/scheduler/buckets.hpp index 967b4408f7..c2cf88c064 100644 --- a/nano/node/scheduler/buckets.hpp +++ b/nano/node/scheduler/buckets.hpp @@ -52,6 +52,7 @@ class buckets final std::size_t bucket_count () const; std::size_t bucket_size (std::size_t index) const; bool empty () const; + bool available () const; void dump () const; std::size_t index (nano::uint128_t const & balance) const; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index e4bd01392e..ffd1954ab1 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -88,7 +88,7 @@ bool nano::scheduler::priority::empty () const bool nano::scheduler::priority::predicate () const { - return node.active.vacancy () > 0 && !buckets->empty (); + return node.active.vacancy () > 0 && buckets->available (); } void nano::scheduler::priority::run ()