From 06857845aa88f18f5e2963c6d9bfdceb6bff0750 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 29 May 2017 10:17:58 +0200 Subject: [PATCH] rec: Mark MT methods as const whenever possible --- pdns/mtasker.cc | 6 +++--- pdns/mtasker.hh | 6 +++--- pdns/pdns_recursor.cc | 10 ++++------ pdns/rec_channel_rec.cc | 9 ++++++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index 9b69507c4..43294c953 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -353,7 +353,7 @@ templatebool MTasker::schedule(struct timeval* n /** Call this to check if no processes are running anymore \return true if no processes are left */ -templatebool MTasker::noProcesses() +templatebool MTasker::noProcesses() const { return d_threads.empty(); } @@ -362,7 +362,7 @@ templatebool MTasker::noProcesses() /** Call this to perhaps limit activities if too many threads are running \return number of processes running */ -templateunsigned int MTasker::numProcesses() +templateunsigned int MTasker::numProcesses() const { return d_threads.size(); } @@ -386,7 +386,7 @@ templatevoid MTasker::getEvents(std::vector& /** Processes can call this to get a numerical representation of their current thread ID. This can be useful for logging purposes. */ -templateint MTasker::getTid() +templateint MTasker::getTid() const { return d_tid; } diff --git a/pdns/mtasker.hh b/pdns/mtasker.hh index ced18d1b4..2014d5bca 100644 --- a/pdns/mtasker.hh +++ b/pdns/mtasker.hh @@ -122,9 +122,9 @@ public: void getEvents(std::vector& events); void makeThread(tfunc_t *start, void* val); bool schedule(struct timeval* now=0); - bool noProcesses(); - unsigned int numProcesses(); - int getTid(); + bool noProcesses() const; + unsigned int numProcesses() const; + int getTid() const; unsigned int getMaxStackUsage(); unsigned int getUsec(); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8c8bb94fc..de6eba32f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -103,12 +103,6 @@ static thread_local std::shared_ptr t_traceRegex; static thread_local std::unique_ptr t_tcpClientCounts; thread_local std::unique_ptr MT; // the big MTasker -MT_t* getMT() -{ - return MT ? MT.get() : 0; -} - - thread_local std::unique_ptr t_RC; thread_local std::unique_ptr t_packetCache; thread_local FDMultiplexer* t_fdm{nullptr}; @@ -227,6 +221,10 @@ struct DNSComboWriter { LuaContext::LuaObject d_data; }; +MT_t* getMT() +{ + return MT ? MT.get() : nullptr; +} ArgvMap &arg() { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index c592b3ca1..6dccf5477 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -601,14 +601,17 @@ static string* pleaseGetCurrentQueries() boost::format fmt("%1% %|40t|%2% %|47t|%3% %|63t|%4% %|68t|%5%\n"); ostr << (fmt % "qname" % "qtype" % "remote" % "tcp" % "chained"); - int n=0; - for(MT_t::waiters_t::iterator mthread=getMT()->d_waiters.begin(); mthread!=getMT()->d_waiters.end() && n < 100; ++mthread, ++n) { - const PacketID& pident = mthread->key; + unsigned int n=0; + for(const auto& mthread : getMT()->d_waiters) { + const PacketID& pident = mthread.key; ostr << (fmt % pident.domain.toLogString() /* ?? */ % DNSRecordContent::NumberToType(pident.type) % pident.remote.toString() % (pident.sock ? 'Y' : 'n') % (pident.fd == -1 ? 'Y' : 'n') ); + ++n; + if (n >= 100) + break; } ostr <<" - done\n"; return new string(ostr.str()); -- 2.40.0