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_; };