From: Remi Gacogne Date: Fri, 8 Jan 2021 16:08:14 +0000 (+0100) Subject: rec: Don't wait on the aggressive cache's locks X-Git-Tag: dnsdist-1.6.0-alpha2~12^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ca87a83bba75886958e62d3909a235bcb5c1ca84;p=thirdparty%2Fpdns.git rec: Don't wait on the aggressive cache's locks --- diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index b35038cd47..0b0b74d4dc 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -36,8 +36,11 @@ std::shared_ptr AggressiveNSECCache::getBestZone { std::shared_ptr entry{nullptr}; { - #warning tryreadlock? - ReadLock rl(d_lock); + TryReadLock rl(d_lock); + if (!rl.gotIt()) { + return entry; + } + auto got = d_zones.lookup(zone); if (got) { return *got; @@ -291,9 +294,8 @@ void AggressiveNSECCache::insertNSEC(const DNSName& zone, const DNSName& owner, bool AggressiveNSECCache::getNSECBefore(time_t now, std::shared_ptr& zoneEntry, const DNSName& name, ZoneEntry::CacheEntry& entry) { - #warning try? - std::lock_guard lock(zoneEntry->d_lock); - if (zoneEntry->d_entries.empty()) { + std::unique_lock lock(zoneEntry->d_lock, std::try_to_lock); + if (!lock.owns_lock() || zoneEntry->d_entries.empty()) { return false; } @@ -347,9 +349,8 @@ bool AggressiveNSECCache::getNSECBefore(time_t now, std::shared_ptr& zoneEntry, const DNSName& name, ZoneEntry::CacheEntry& entry) { - #warning try? - std::lock_guard lock(zoneEntry->d_lock); - if (zoneEntry->d_entries.empty()) { + std::unique_lock lock(zoneEntry->d_lock, std::try_to_lock); + if (!lock.owns_lock() || zoneEntry->d_entries.empty()) { return false; }