Skip to content

Commit

Permalink
Use priority limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 12, 2023
1 parent e30999a commit be198bf
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <nano/node/node.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/limiter.hpp>
#include <nano/node/scheduler/priority.hpp>

nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) :
Expand Down Expand Up @@ -124,30 +125,42 @@ void nano::scheduler::priority::run ()
if (manual_queue_predicate ())
{
auto const [block, previous_balance, election_behavior] = manual_queue.front ();
manual_queue.pop_front ();
lock.unlock ();
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual);
auto result = node.active.insert (block, election_behavior);
if (result.election != nullptr)
if (result.election)
{
result.election->transition_active ();
manual_queue.pop_front ();
}
else
{
std::cerr << '\0';
}
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual);
}
else if (priority_queue_predicate ())
{
auto block = buckets->top ();
buckets->pop ();
lock.unlock ();
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority);
auto result = node.active.insert (block.first);
if (result.inserted)
if (!buckets->top ().second->available ())
{
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success);
buckets->seek ();
}
auto [block, limiter] = buckets->top ();
debug_assert (limiter->available ());
auto result = limiter->activate (block);
if (result.election != nullptr)
{
buckets->pop ();
lock.unlock ();
result.election->transition_active ();
if (result.inserted)
{
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success);
}
}
else
{
lock.unlock ();
}
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority);
}
else
{
Expand Down

0 comments on commit be198bf

Please sign in to comment.