diff --git a/asio/include/asio/detail/impl/epoll_reactor.ipp b/asio/include/asio/detail/impl/epoll_reactor.ipp index a2ddae4d..d72737b6 100644 --- a/asio/include/asio/detail/impl/epoll_reactor.ipp +++ b/asio/include/asio/detail/impl/epoll_reactor.ipp @@ -635,7 +635,7 @@ struct epoll_reactor::perform_io_cleanup_on_block_exit // No user-initiated operations have completed, so we need to compensate // for the work_finished() call that the scheduler will make once this // operation returns. - reactor_->scheduler_.work_started(); + reactor_->scheduler_.compensating_work_started(); } } diff --git a/asio/include/asio/detail/impl/scheduler.ipp b/asio/include/asio/detail/impl/scheduler.ipp index 8145651c..66c9009a 100644 --- a/asio/include/asio/detail/impl/scheduler.ipp +++ b/asio/include/asio/detail/impl/scheduler.ipp @@ -243,6 +243,12 @@ void scheduler::restart() stopped_ = false; } +void scheduler::compensating_work_started() +{ + thread_info_base* this_thread = thread_call_stack::contains(this); + ++static_cast(this_thread)->private_outstanding_work; +} + void scheduler::post_immediate_completion( scheduler::operation* op, bool is_continuation) { diff --git a/asio/include/asio/detail/scheduler.hpp b/asio/include/asio/detail/scheduler.hpp index 0589a99c..fa804948 100644 --- a/asio/include/asio/detail/scheduler.hpp +++ b/asio/include/asio/detail/scheduler.hpp @@ -79,6 +79,10 @@ public: ++outstanding_work_; } + // Used to compensate for a forthcoming work_finished call. Must be called + // from within a scheduler-owned thread. + ASIO_DECL void compensating_work_started(); + // Notify that some work has finished. void work_finished() {