From ca75c9125d8b0e71789211361b36fef47ff916f0 Mon Sep 17 00:00:00 2001 From: Valeri Ochinski Date: Fri, 13 Oct 2023 18:51:11 +0300 Subject: common/polyfill_thread: use std::forward where appropriate, qualify std::move calls --- src/common/polyfill_thread.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/common/polyfill_thread.h b/src/common/polyfill_thread.h index 41cbb9ed5..12e59a893 100644 --- a/src/common/polyfill_thread.h +++ b/src/common/polyfill_thread.h @@ -15,12 +15,13 @@ #include #include #include +#include namespace Common { template void CondvarWait(Condvar& cv, std::unique_lock& lk, std::stop_token token, Pred&& pred) { - cv.wait(lk, token, std::move(pred)); + cv.wait(lk, token, std::forward(pred)); } template @@ -109,7 +110,7 @@ public: // Insert the callback. stop_state_callback ret = ++m_next_callback; - m_callbacks.emplace(ret, move(f)); + m_callbacks.emplace(ret, std::move(f)); return ret; } @@ -162,7 +163,7 @@ private: friend class stop_source; template friend class stop_callback; - stop_token(shared_ptr stop_state) : m_stop_state(move(stop_state)) {} + stop_token(shared_ptr stop_state) : m_stop_state(std::move(stop_state)) {} private: shared_ptr m_stop_state; @@ -198,7 +199,7 @@ public: private: friend class jthread; explicit stop_source(shared_ptr stop_state) - : m_stop_state(move(stop_state)) {} + : m_stop_state(std::move(stop_state)) {} private: shared_ptr m_stop_state; @@ -218,16 +219,16 @@ public: C&& cb) noexcept(is_nothrow_constructible_v) : m_stop_state(st.m_stop_state) { if (m_stop_state) { - m_callback = m_stop_state->insert_callback(move(cb)); + m_callback = m_stop_state->insert_callback(std::move(cb)); } } template requires constructible_from explicit stop_callback(stop_token&& st, C&& cb) noexcept(is_nothrow_constructible_v) - : m_stop_state(move(st.m_stop_state)) { + : m_stop_state(std::move(st.m_stop_state)) { if (m_stop_state) { - m_callback = m_stop_state->insert_callback(move(cb)); + m_callback = m_stop_state->insert_callback(std::move(cb)); } } ~stop_callback() { @@ -260,7 +261,7 @@ public: typename = enable_if_t, jthread>>> explicit jthread(F&& f, Args&&... args) : m_stop_state(make_shared()), - m_thread(make_thread(move(f), move(args)...)) {} + m_thread(make_thread(std::forward(f), std::forward(args)...)) {} ~jthread() { if (joinable()) { @@ -317,9 +318,9 @@ private: template thread make_thread(F&& f, Args&&... args) { if constexpr (is_invocable_v, stop_token, decay_t...>) { - return thread(move(f), get_stop_token(), move(args)...); + return thread(std::forward(f), get_stop_token(), std::forward(args)...); } else { - return thread(move(f), move(args)...); + return thread(std::forward(f), std::forward(args)...); } } -- cgit v1.2.3