From 13937c5a8876e7caedd3504d818a41b1baa6d49d Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 11 Jan 2023 12:27:23 +0100 Subject: [PATCH] dnsdist: Apply suggestions from Otto's code review (thanks!) --- pdns/dnsdist-idstate.hh | 7 +++---- pdns/dnsdistdist/dnsdist-backend.cc | 15 +++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) 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); -- 2.47.2