Skip to content

Commit

Permalink
Add "scheduler" / "task_usec" (long) config parameter.
Browse files Browse the repository at this point in the history
Specifies the maximum time that the scheduler will allow its task
(usually a reactor) to run. Set to 0 to enable spinning.
  • Loading branch information
chriskohlhoff committed Oct 30, 2024
1 parent 79163e4 commit bb85475
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion asio/include/asio/detail/impl/scheduler.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ scheduler::scheduler(asio::execution_context& ctx,
stopped_(false),
shutdown_(false),
concurrency_hint_(config(ctx).get("scheduler", "concurrency_hint", 0)),
task_usec_(config(ctx).get("scheduler", "task_usec", -1)),
thread_(0)
{
ASIO_HANDLER_TRACKING_INIT;
Expand Down Expand Up @@ -468,7 +469,8 @@ std::size_t scheduler::do_run_one(mutex::scoped_lock& lock,
// Run the task. May throw an exception. Only block if the operation
// queue is empty and we're not polling, otherwise we want to return
// as soon as possible.
task_->run(more_handlers ? 0 : -1, this_thread.private_op_queue);
task_->run(more_handlers ? 0 : task_usec_,
this_thread.private_op_queue);
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions asio/include/asio/detail/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class scheduler
// The concurrency hint used to initialise the scheduler.
const int concurrency_hint_;

// The time limit on running the scheduler task, in microseconds.
const long task_usec_;

// The thread that is running the scheduler.
asio::detail::thread* thread_;
};
Expand Down

0 comments on commit bb85475

Please sign in to comment.