]> granicus.if.org Git - pdns/commitdiff
rec: Mark MT methods as const whenever possible
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 29 May 2017 08:17:58 +0000 (10:17 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 29 May 2017 09:18:29 +0000 (11:18 +0200)
pdns/mtasker.cc
pdns/mtasker.hh
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc

index 9b69507c4139d0ee272996d7a6f41dbfb28a3140..43294c9537cce1a005415dd9c86063c8cf926083 100644 (file)
@@ -353,7 +353,7 @@ template<class Key, class Val>bool MTasker<Key,Val>::schedule(struct timeval*  n
 /** Call this to check if no processes are running anymore
     \return true if no processes are left
  */
-template<class Key, class Val>bool MTasker<Key,Val>::noProcesses()
+template<class Key, class Val>bool MTasker<Key,Val>::noProcesses() const
 {
   return d_threads.empty();
 }
@@ -362,7 +362,7 @@ template<class Key, class Val>bool MTasker<Key,Val>::noProcesses()
 /** Call this to perhaps limit activities if too many threads are running
     \return number of processes running
  */
-template<class Key, class Val>unsigned int MTasker<Key,Val>::numProcesses()
+template<class Key, class Val>unsigned int MTasker<Key,Val>::numProcesses() const
 {
   return d_threads.size();
 }
@@ -386,7 +386,7 @@ template<class Key, class Val>void MTasker<Key,Val>::getEvents(std::vector<Key>&
 /** Processes can call this to get a numerical representation of their current thread ID.
     This can be useful for logging purposes.
 */
-template<class Key, class Val>int MTasker<Key,Val>::getTid()
+template<class Key, class Val>int MTasker<Key,Val>::getTid() const
 {
   return d_tid;
 }
index ced18d1b4a942f3524ba45825e3b3ab05bb718c9..2014d5bcae6566109a492bab28ae9404253a7237 100644 (file)
@@ -122,9 +122,9 @@ public:
   void getEvents(std::vector<EventKey>& 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();
 
index 8c8bb94fce9baed1809622e45fc22fa13c6cbc09..de6eba32f52df80703f83c13fae2522e38bf057d 100644 (file)
@@ -103,12 +103,6 @@ static thread_local std::shared_ptr<Regex> t_traceRegex;
 static thread_local std::unique_ptr<tcpClientCounts_t> t_tcpClientCounts;
 
 thread_local std::unique_ptr<MT_t> MT; // the big MTasker
-MT_t* getMT()
-{
-  return MT ? MT.get() : 0;
-}
-
-
 thread_local std::unique_ptr<MemRecursorCache> t_RC;
 thread_local std::unique_ptr<RecursorPacketCache> 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()
 {
index c592b3ca1227f6041e0a21507317991e416bcf87..6dccf5477288aa24df56a995fd107deab6e9d376 100644 (file)
@@ -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());