From: Remi Gacogne Date: Fri, 4 Jun 2021 15:27:19 +0000 (+0200) Subject: auth: Convert Lua records to SharedLockGuarded X-Git-Tag: dnsdist-1.7.0-alpha1~11^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbbfdc22a8951e806ebeba8ff3cfff7c4da15a02;p=thirdparty%2Fpdns.git auth: Convert Lua records to SharedLockGuarded --- diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index d2d7ba3347..12c1f83dac 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -73,7 +73,6 @@ private: std::atomic lastAccess{0}; }; - ReadWriteLock d_lock; public: IsUpOracle() { @@ -158,8 +157,9 @@ private: std::vector> results; std::vector toDelete; { - ReadLock lock{&d_lock}; // make sure there's no insertion - for (auto& it: d_statuses) { + // make sure there's no insertion + auto statuses = d_statuses.read_lock(); + for (auto& it: *statuses) { auto& desc = it.first; auto& state = it.second; @@ -178,9 +178,9 @@ private: future.wait(); } if (!toDelete.empty()) { - WriteLock lock{&d_lock}; + auto statuses = d_statuses.write_lock(); for (auto& it: toDelete) { - d_statuses.erase(it); + statuses->erase(it); } } std::this_thread::sleep_until(checkStart + std::chrono::seconds(g_luaHealthChecksInterval)); @@ -188,14 +188,14 @@ private: } typedef map> statuses_t; - statuses_t d_statuses; + SharedLockGuarded d_statuses; std::unique_ptr d_checkerThread; void setStatus(const CheckDesc& cd, bool status) { - ReadLock lock{&d_lock}; - auto& state = d_statuses[cd]; + auto statuses = d_statuses.write_lock(); + auto& state = (*statuses)[cd]; state->status = status; if (state->first) { state->first = false; @@ -233,9 +233,9 @@ bool IsUpOracle::isUp(const CheckDesc& cd) } time_t now = time(nullptr); { - ReadLock lock{&d_lock}; - auto iter = d_statuses.find(cd); - if (iter != d_statuses.end()) { + auto statuses = d_statuses.read_lock(); + auto iter = statuses->find(cd); + if (iter != statuses->end()) { iter->second->lastAccess = now; return iter->second->status; } @@ -245,10 +245,10 @@ bool IsUpOracle::isUp(const CheckDesc& cd) ComboAddress src(cd.opts.at("source")); } { - WriteLock lock{&d_lock}; + auto statuses = d_statuses.write_lock(); // Make sure we don't insert new entry twice now we have the lock - if (d_statuses.find(cd) == d_statuses.end()) { - d_statuses[cd] = std::unique_ptr(new CheckState{now}); + if (statuses->find(cd) == statuses->end()) { + (*statuses)[cd] = std::unique_ptr(new CheckState{now}); } } return false;