From bb85475e13d73373fdb4928bfcb96e5ca4853018 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Tue, 29 Oct 2024 23:38:42 +1100 Subject: [PATCH] Add "scheduler" / "task_usec" (long) config parameter. Specifies the maximum time that the scheduler will allow its task (usually a reactor) to run. Set to 0 to enable spinning. --- asio/include/asio/detail/impl/scheduler.ipp | 4 +++- asio/include/asio/detail/scheduler.hpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/asio/include/asio/detail/impl/scheduler.ipp b/asio/include/asio/detail/impl/scheduler.ipp index e633f21d5d..de0da55506 100644 --- a/asio/include/asio/detail/impl/scheduler.ipp +++ b/asio/include/asio/detail/impl/scheduler.ipp @@ -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; @@ -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 { diff --git a/asio/include/asio/detail/scheduler.hpp b/asio/include/asio/detail/scheduler.hpp index 6cf80148dd..32778e0af5 100644 --- a/asio/include/asio/detail/scheduler.hpp +++ b/asio/include/asio/detail/scheduler.hpp @@ -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_; };