From: Remi Gacogne Date: Mon, 18 Nov 2019 09:11:58 +0000 (+0100) Subject: Use move semantics when updating the content of the StateHolder X-Git-Tag: auth-4.3.0-alpha1~34^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=33c2fd8af7b0f2968c7a78e9dc142b0cdd798a55;p=thirdparty%2Fpdns.git Use move semantics when updating the content of the StateHolder --- diff --git a/pdns/sholder.hh b/pdns/sholder.hh index 75837c30f1..ce5da43ce3 100644 --- a/pdns/sholder.hh +++ b/pdns/sholder.hh @@ -92,12 +92,22 @@ public: return LocalStateHolder(this); } - void setState(T state) //!< Safely & slowly change the global state + void setState(const T& state) //!< Safely & slowly change the global state { std::shared_ptr newState = std::make_shared(state); { std::lock_guard l(d_lock); - d_state = newState; + d_state = std::move(newState); + d_generation++; + } + } + + void setState(T&& state) //!< Safely & slowly change the global state + { + std::shared_ptr newState = std::make_shared(std::move(state)); + { + std::lock_guard l(d_lock); + d_state = std::move(newState); d_generation++; } } @@ -111,10 +121,10 @@ public: //! Safely & slowly modify the global state template void modify(F act) { - std::lock_guard l(d_lock); + std::lock_guard l(d_lock); auto state=*d_state; // and yes, these three steps are necessary, can't ever modify state in place, even when locked! act(state); - d_state = std::make_shared(state); + d_state = std::make_shared(std::move(state)); ++d_generation; }