From 6e41eb901a0f40196c329255d7ca6bb22892b87b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 19 May 2021 12:57:09 +0200 Subject: [PATCH] Rename the lock() method to write_lock() for shared mutexes --- pdns/dnscrypt.cc | 12 ++++++------ pdns/dnsdist-cache.cc | 10 +++++----- pdns/dnsdist-cache.hh | 2 +- pdns/dnsdist-carbon.cc | 2 +- pdns/dnsdist-lua.cc | 2 +- pdns/dnsdist.cc | 2 +- pdns/dnsdistdist/dnsdist-backend.cc | 6 +++--- pdns/dnsdistdist/dnsdist-kvs.cc | 2 +- pdns/dnsdistdist/dnsdist-rules.hh | 16 ++++++++-------- pdns/libssl.cc | 4 ++-- pdns/lock.hh | 4 ++-- pdns/recursordist/aggressive_nsec.cc | 10 +++++----- pdns/tcpiohandler.cc | 4 ++-- 13 files changed, 38 insertions(+), 38 deletions(-) diff --git a/pdns/dnscrypt.cc b/pdns/dnscrypt.cc index 71bfe6ced9..9a803958fd 100644 --- a/pdns/dnscrypt.cc +++ b/pdns/dnscrypt.cc @@ -284,7 +284,7 @@ std::string DNSCryptContext::certificateDateToStr(uint32_t date) void DNSCryptContext::addNewCertificate(std::shared_ptr& newCert, bool reload) { - auto certs = d_certs.lock(); + auto certs = d_certs.write_lock(); for (auto pair : *certs) { if (pair->cert.getSerial() == newCert->cert.getSerial()) { @@ -327,7 +327,7 @@ void DNSCryptContext::loadNewCertificate(const std::string& certFile, const std: auto newPair = DNSCryptContext::loadCertificatePair(certFile, keyFile); newPair->active = active; addNewCertificate(newPair, reload); - d_certKeyPaths.lock()->push_back({certFile, keyFile}); + d_certKeyPaths.write_lock()->push_back({certFile, keyFile}); } void DNSCryptContext::reloadCertificates() @@ -342,7 +342,7 @@ void DNSCryptContext::reloadCertificates() } { - *(d_certs.lock()) = std::move(newCerts); + *(d_certs.write_lock()) = std::move(newCerts); } } @@ -353,7 +353,7 @@ std::vector> DNSCryptContext::getCertif void DNSCryptContext::markActive(uint32_t serial) { - for (auto pair : *d_certs.lock()) { + for (auto pair : *d_certs.write_lock()) { if (pair->active == false && pair->cert.getSerial() == serial) { pair->active = true; return; @@ -364,7 +364,7 @@ void DNSCryptContext::markActive(uint32_t serial) void DNSCryptContext::markInactive(uint32_t serial) { - for (auto pair : *d_certs.lock()) { + for (auto pair : *d_certs.write_lock()) { if (pair->active == true && pair->cert.getSerial() == serial) { pair->active = false; return; @@ -375,7 +375,7 @@ void DNSCryptContext::markInactive(uint32_t serial) void DNSCryptContext::removeInactiveCertificate(uint32_t serial) { - auto certs = d_certs.lock(); + auto certs = d_certs.write_lock(); for (auto it = certs->begin(); it != certs->end(); ) { if ((*it)->active == false && (*it)->cert.getSerial() == serial) { diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 266a1cb05c..8b41f68454 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -174,7 +174,7 @@ void DNSDistPacketCache::insert(uint32_t key, const boost::optional& su auto& shard = d_shards.at(shardIndex); if (d_deferrableInsertLock) { - auto w = shard.d_map.try_lock(); + auto w = shard.d_map.try_write_lock(); if (!w.owns_lock()) { d_deferredInserts++; @@ -183,7 +183,7 @@ void DNSDistPacketCache::insert(uint32_t key, const boost::optional& su insertLocked(shard, *w, key, newValue); } else { - auto w = shard.d_map.lock(); + auto w = shard.d_map.write_lock(); insertLocked(shard, *w, key, newValue); } @@ -296,7 +296,7 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now) size_t removed = 0; for (auto& shard : d_shards) { - auto map = shard.d_map.lock(); + auto map = shard.d_map.write_lock(); if (map->size() <= maxPerShard) { continue; } @@ -332,7 +332,7 @@ size_t DNSDistPacketCache::expunge(size_t upTo) size_t removed = 0; for (auto& shard : d_shards) { - auto map = shard.d_map.lock(); + auto map = shard.d_map.write_lock(); if (map->size() <= maxPerShard) { continue; @@ -364,7 +364,7 @@ size_t DNSDistPacketCache::expungeByName(const DNSName& name, uint16_t qtype, bo size_t removed = 0; for (auto& shard : d_shards) { - auto map = shard.d_map.lock(); + auto map = shard.d_map.write_lock(); for(auto it = map->begin(); it != map->end(); ) { const CacheValue& value = it->second; diff --git a/pdns/dnsdist-cache.hh b/pdns/dnsdist-cache.hh index 33c03eef56..0fbcb772b9 100644 --- a/pdns/dnsdist-cache.hh +++ b/pdns/dnsdist-cache.hh @@ -112,7 +112,7 @@ private: void setSize(size_t maxSize) { - d_map.lock()->reserve(maxSize); + d_map.write_lock()->reserve(maxSize); } SharedLockGuarded> d_map; diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index e9d169e8a0..afbe27decd 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -239,7 +239,7 @@ void carbonDumpThread() { std::string qname; - auto records = g_qcount.records.lock(); + auto records = g_qcount.records.write_lock(); for (const auto &record : *records) { qname = record.first; boost::replace_all(qname, ".", "_"); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index cce08db5f5..879b785e5a 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1046,7 +1046,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) luaCtx.writeFunction("clearQueryCounters", []() { unsigned int size{0}; { - auto records = g_qcount.records.lock(); + auto records = g_qcount.records.write_lock(); size = records->size(); records->clear(); } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index f4b5804ee5..5413127064 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -854,7 +854,7 @@ static bool applyRulesToQuery(LocalHolders& holders, DNSQuestion& dq, const stru } if (countQuery) { - auto records = g_qcount.records.lock(); + auto records = g_qcount.records.write_lock(); if (!records->count(qname)) { (*records)[qname] = 0; } diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index ad290d17db..d0ffe2eecb 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -117,7 +117,7 @@ void DownstreamState::hash() { vinfolog("Computing hashes for id=%s and weight=%d", id, weight); auto w = weight; - auto lockedHashes = hashes.lock(); + auto lockedHashes = hashes.write_lock(); lockedHashes->clear(); lockedHashes->reserve(w); while (w > 0) { @@ -216,7 +216,7 @@ const std::shared_ptr ServerPool::getServers void ServerPool::addServer(shared_ptr& server) { - auto servers = d_servers.lock(); + auto servers = d_servers.write_lock(); /* we can't update the content of the shared pointer directly even when holding the lock, as other threads might hold a copy. We can however update the pointer as long as we hold the lock. */ unsigned int count = static_cast((*servers)->size()); @@ -236,7 +236,7 @@ void ServerPool::addServer(shared_ptr& server) void ServerPool::removeServer(shared_ptr& server) { - auto servers = d_servers.lock(); + auto servers = d_servers.write_lock(); /* we can't update the content of the shared pointer directly even when holding the lock, as other threads might hold a copy. We can however update the pointer as long as we hold the lock. */ auto newServers = std::make_shared(*(*servers)); diff --git a/pdns/dnsdistdist/dnsdist-kvs.cc b/pdns/dnsdistdist/dnsdist-kvs.cc index bc43e8f26e..ead0e10965 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.cc +++ b/pdns/dnsdistdist/dnsdist-kvs.cc @@ -192,7 +192,7 @@ bool CDBKVStore::reload(const struct stat& st) { auto newCDB = std::unique_ptr(new CDB(d_fname)); { - *(d_cdb.lock()) = std::move(newCDB); + *(d_cdb.write_lock()) = std::move(newCDB); } d_mtime = st.st_mtime; return true; diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index 89b7cae813..6e0e5d9232 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -258,13 +258,13 @@ public: { // think twice before adding templates here if (ca.sin4.sin_family == AF_INET) { - auto res = d_ip4s.lock()->insert({ca.sin4.sin_addr.s_addr, ttd}); + auto res = d_ip4s.write_lock()->insert({ca.sin4.sin_addr.s_addr, ttd}); if (!res.second && (time_t)res.first->second < ttd) { res.first->second = (uint32_t)ttd; } } else { - auto res = d_ip6s.lock()->insert({{ca}, ttd}); + auto res = d_ip6s.write_lock()->insert({{ca}, ttd}); if (!res.second && (time_t)res.first->second < ttd) { res.first->second = (uint32_t)ttd; } @@ -274,24 +274,24 @@ public: void remove(const ComboAddress& ca) { if (ca.sin4.sin_family == AF_INET) { - d_ip4s.lock()->erase(ca.sin4.sin_addr.s_addr); + d_ip4s.write_lock()->erase(ca.sin4.sin_addr.s_addr); } else { - d_ip6s.lock()->erase({ca}); + d_ip6s.write_lock()->erase({ca}); } } void clear() { - d_ip4s.lock()->clear(); - d_ip6s.lock()->clear(); + d_ip4s.write_lock()->clear(); + d_ip6s.write_lock()->clear(); } void cleanup() { time_t now = time(nullptr); { - auto ip4s = d_ip4s.lock(); + auto ip4s = d_ip4s.write_lock(); for (auto iter = ip4s->begin(); iter != ip4s->end(); ) { if (iter->second < now) { iter = ip4s->erase(iter); @@ -303,7 +303,7 @@ public: } { - auto ip6s = d_ip6s.lock(); + auto ip6s = d_ip6s.write_lock(); for (auto iter = ip6s->begin(); iter != ip6s->end(); ) { if (iter->second < now) { iter = ip6s->erase(iter); diff --git a/pdns/libssl.cc b/pdns/libssl.cc index 2d2a717b82..b667d27d01 100644 --- a/pdns/libssl.cc +++ b/pdns/libssl.cc @@ -493,7 +493,7 @@ bool libssl_set_min_tls_version(std::unique_ptr& ctx OpenSSLTLSTicketKeysRing::OpenSSLTLSTicketKeysRing(size_t capacity) { - d_ticketKeys.lock()->set_capacity(capacity); + d_ticketKeys.write_lock()->set_capacity(capacity); } OpenSSLTLSTicketKeysRing::~OpenSSLTLSTicketKeysRing() @@ -502,7 +502,7 @@ OpenSSLTLSTicketKeysRing::~OpenSSLTLSTicketKeysRing() void OpenSSLTLSTicketKeysRing::addKey(std::shared_ptr newKey) { - d_ticketKeys.lock()->push_front(newKey); + d_ticketKeys.write_lock()->push_front(newKey); } std::shared_ptr OpenSSLTLSTicketKeysRing::getEncryptionKey() diff --git a/pdns/lock.hh b/pdns/lock.hh index fa1d4c2603..fbf94bf836 100644 --- a/pdns/lock.hh +++ b/pdns/lock.hh @@ -364,12 +364,12 @@ public: { } - SharedLockGuardedTryHolder try_lock() + SharedLockGuardedTryHolder try_write_lock() { return SharedLockGuardedTryHolder(d_value, d_mutex); } - SharedLockGuardedHolder lock() + SharedLockGuardedHolder write_lock() { return SharedLockGuardedHolder(d_value, d_mutex); } diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index b56784007b..9368e4a865 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -65,7 +65,7 @@ std::shared_ptr> AggressiveNSECCache auto entry = std::make_shared>(zone); { - auto zones = d_zones.lock(); + auto zones = d_zones.write_lock(); /* it might have been inserted in the mean time */ auto got = zones->lookup(zone); if (got && *got) { @@ -92,7 +92,7 @@ void AggressiveNSECCache::updateEntriesCount(SuffixMatchTreeremove(zone, true); @@ -134,7 +134,7 @@ void AggressiveNSECCache::prune(time_t now) toLook = toErase * 5; // we are full, scan at max 5 * toErase entries and stop once we have nuked enough - auto zones = d_zones.lock(); + auto zones = d_zones.write_lock(); zones->visit([now, &erased, toErase, toLook, &lookedAt, &emptyEntries](const SuffixMatchTree>>& node) { if (!node.d_value || erased > toErase || lookedAt > toLook) { return; @@ -163,7 +163,7 @@ void AggressiveNSECCache::prune(time_t now) } else { // we are not full, just look through 10% of the cache and nuke everything that is expired - auto zones = d_zones.lock(); + auto zones = d_zones.write_lock(); zones->visit([now, &erased, toLook, &lookedAt, &emptyEntries](const SuffixMatchTree>>& node) { if (!node.d_value) { return; @@ -193,7 +193,7 @@ void AggressiveNSECCache::prune(time_t now) d_entriesCount -= erased; if (!emptyEntries.empty()) { - auto zones = d_zones.lock(); + auto zones = d_zones.write_lock(); for (const auto& entry : emptyEntries) { zones->remove(entry); } diff --git a/pdns/tcpiohandler.cc b/pdns/tcpiohandler.cc index 40137041b0..daa49a1a59 100644 --- a/pdns/tcpiohandler.cc +++ b/pdns/tcpiohandler.cc @@ -1175,7 +1175,7 @@ public: auto newKey = std::make_shared(); { - *(d_ticketsKey.lock()) = newKey; + *(d_ticketsKey.write_lock()) = newKey; } if (d_ticketsKeyRotationDelay > 0) { @@ -1191,7 +1191,7 @@ public: auto newKey = std::make_shared(file); { - *(d_ticketsKey.lock()) = newKey; + *(d_ticketsKey.write_lock()) = newKey; } if (d_ticketsKeyRotationDelay > 0) { -- 2.47.2