]> granicus.if.org Git - pdns/commitdiff
rec: Use constants for the handler and distributor thread ids
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 3 May 2018 14:01:46 +0000 (15:01 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 15 May 2018 13:23:01 +0000 (15:23 +0200)
(cherry picked from commit badb05fe4c358ab8f206f4a7842368d87bd90415)

pdns/pdns_recursor.cc

index bcc15d2f716c81d9ca90ca340147eafaf9c8d048..8394230847360cb9b75d9513cff7e4dc76a0fb06 100644 (file)
@@ -122,6 +122,9 @@ struct ThreadPipeSet
   int readFromThread;
 };
 
+static const int s_handlerThreadID = -1;
+static const int s_distributorThreadID = 0;
+
 typedef vector<int> tcpListenSockets_t;
 typedef map<int, ComboAddress> listenSocketsAddresses_t; // is shared across all threads right now
 typedef vector<pair<int, function< void(int, any&) > > > deferredAdd_t;
@@ -2172,13 +2175,13 @@ static void houseKeeping(void *)
         last_rootupdate=now.tv_sec;
     }
 
-    if (t_id == -1) {
+    if (t_id == s_handlerThreadID) {
       if(g_statisticsInterval > 0 && now.tv_sec - last_stat >= g_statisticsInterval) {
        doStats();
        last_stat=time(0);
       }
     }
-    else if(!t_id) {
+    else if(t_id == s_distributorThreadID) {
 
       if(now.tv_sec - last_secpoll >= 3600) {
        try {
@@ -2242,7 +2245,7 @@ struct ThreadMSG
 void broadcastFunction(const pipefunc_t& func, bool skipSelf)
 {
   /* This function might be called by the worker with t_id 0 during startup */
-  if (t_id != -1 && t_id != 0) {
+  if (t_id != s_handlerThreadID && t_id != s_distributorThreadID) {
     L<<Logger::Error<<"broadcastFunction() has been called by a worker ("<<t_id<<")"<<endl;
     exit(1);
   }
@@ -2277,7 +2280,7 @@ void broadcastFunction(const pipefunc_t& func, bool skipSelf)
 
 void distributeAsyncFunction(const string& packet, const pipefunc_t& func)
 {
-  if (t_id != 0) {
+  if (t_id != s_distributorThreadID) {
     L<<Logger::Error<<"distributeAsyncFunction() has been called by a worker ("<<t_id<<")"<<endl;
     exit(1);
   }
@@ -2357,7 +2360,7 @@ vector<pair<DNSName, uint16_t> >& operator+=(vector<pair<DNSName, uint16_t> >&a,
 
 template<class T> T broadcastAccFunction(const boost::function<T*()>& func, bool skipSelf)
 {
-  if (t_id != -1) {
+  if (t_id != s_handlerThreadID) {
     L<<Logger::Error<<"broadcastFunction has been called by a worker ("<<t_id<<")"<<endl;
     exit(1);
 
@@ -3143,7 +3146,7 @@ static int serviceMain(int argc, char*argv[])
   }
 
   /* This thread handles the web server, carbon, statistics and the control channel */
-  std::thread handlerThread(recursorThread, -1, false);
+  std::thread handlerThread(recursorThread, s_handlerThreadID, false);
 
   const auto cpusMap = parseCPUMap();
 
@@ -3246,7 +3249,7 @@ try
       }
     }
     else {
-      if(!g_weDistributeQueries || !t_id) { // if we distribute queries, only t_id = 0 listens
+      if(!g_weDistributeQueries || t_id == s_distributorThreadID) { // if we distribute queries, only t_id = 0 listens
         for(deferredAdd_t::const_iterator i = deferredAdds[0].cbegin(); i != deferredAdds[0].cend(); ++i) {
           t_fdm->addReadFD(i->first, i->second);
         }
@@ -3302,7 +3305,7 @@ try
     t_fdm->run(&g_now);
     // 'run' updates g_now for us
 
-    if(worker && (!g_weDistributeQueries || !t_id)) { // if pdns distributes queries, only tid 0 should do this
+    if(worker && (!g_weDistributeQueries || t_id == s_distributorThreadID)) { // if pdns distributes queries, only tid 0 should do this
       if(listenOnTCP) {
        if(TCPConnection::getCurrentConnections() > maxTcpClients) {  // shutdown, too many connections
          for(tcpListenSockets_t::iterator i=g_tcpListenSockets.begin(); i != g_tcpListenSockets.end(); ++i)