diff --git a/include/seastar/core/thread.hh b/include/seastar/core/thread.hh index 85750afd0b..14811fb6e4 100644 --- a/include/seastar/core/thread.hh +++ b/include/seastar/core/thread.hh @@ -183,13 +183,19 @@ public: /// /// Useful where we cannot call yield() immediately because we /// Need to take some cleanup action first. - static bool should_yield(); + static bool should_yield() { + return need_preempt(); + } /// \brief Yield if this thread ought to call yield() now. /// /// Useful where a code does long running computation and does /// not want to hog cpu for more then its share - static void maybe_yield(); + static void maybe_yield() { + if (should_yield()) [[unlikely]] { + yield(); + } + } static bool running_in_thread() { return thread_impl::get() != nullptr; diff --git a/src/core/thread.cc b/src/core/thread.cc index c5d81db299..228cea2c66 100644 --- a/src/core/thread.cc +++ b/src/core/thread.cc @@ -354,17 +354,6 @@ void thread::yield() { thread_impl::get()->yield(); } -bool thread::should_yield() { - return thread_impl::get()->should_yield(); -} - -void thread::maybe_yield() { - auto tctx = thread_impl::get(); - if (tctx->should_yield()) { - tctx->yield(); - } -} - } /// \endcond