From: Remi Gacogne Date: Wed, 11 Jan 2023 11:27:23 +0000 (+0100) Subject: dnsdist: Apply suggestions from Otto's code review (thanks!) X-Git-Tag: dnsdist-1.8.0-rc1~123^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=13937c5a8876e7caedd3504d818a41b1baa6d49d;p=thirdparty%2Fpdns.git dnsdist: Apply suggestions from Otto's code review (thanks!) --- diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index 1fb8116be1..5654716647 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -160,14 +160,13 @@ struct IDState } IDState(const IDState& orig) = delete; - IDState(IDState&& rhs) + IDState(IDState&& rhs) noexcept: internal(std::move(rhs.internal)) { inUse.store(rhs.inUse.load()); age.store(rhs.age.load()); - internal = std::move(rhs.internal); } - IDState& operator=(IDState&& rhs) + IDState& operator=(IDState&& rhs) noexcept { inUse.store(rhs.inUse.load()); age.store(rhs.age.load()); @@ -177,7 +176,7 @@ struct IDState bool isInUse() const { - return inUse == true; + return inUse; } /* For performance reasons we don't want to use a lock here, but that means diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index eea141e440..f1183c2e51 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -447,17 +447,16 @@ uint16_t DownstreamState::saveState(InternalQueryState&& state) } do { - IDState* ids = nullptr; uint16_t selectedID = (idOffset++) % idStates.size(); - ids = &idStates[selectedID]; - auto guard = ids->acquire(); + IDState& ids = idStates[selectedID]; + auto guard = ids.acquire(); if (!guard) { continue; } - if (ids->isInUse()) { + if (ids.isInUse()) { /* we are reusing a state, no change in outstanding but if there was an existing DOHUnit we need to handle it because it's about to be overwritten. */ - auto oldDU = std::move(ids->internal.du); + auto oldDU = std::move(ids.internal.du); ++reuseds; ++g_stats.downstreamTimeouts; handleDOHTimeout(std::move(oldDU)); @@ -465,9 +464,9 @@ uint16_t DownstreamState::saveState(InternalQueryState&& state) else { ++outstanding; } - ids->internal = std::move(state); - ids->age.store(0); - ids->inUse = true; + ids.internal = std::move(state); + ids.age.store(0); + ids.inUse = true; return selectedID; } while (true);