]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Change TaskQueue to be no longer thread local
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 25 Jan 2022 14:42:05 +0000 (15:42 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 4 Feb 2022 10:06:16 +0000 (11:06 +0100)
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-taskqueue.cc
pdns/recursordist/taskqueue.cc
pdns/recursordist/taskqueue.hh

index b00e42f9d41a6d4dd63a1ae836e89699079b7709..9f3a63db61bc30d2823caecddf46d8d6ed7ae970 100644 (file)
@@ -1801,8 +1801,6 @@ static void houseKeeping(void*)
     }
     t_running = true;
 
-    runTaskOnce(g_logCommonErrors);
-
     struct timeval now, past;
     Utility::gettimeofday(&now, nullptr);
     past = now;
@@ -1822,7 +1820,10 @@ static void houseKeeping(void*)
       Utility::gettimeofday(&t_last_prune, nullptr);
     }
 
-    if (RecThreadInfo::self().isHandler()) {
+    const auto& info = RecThreadInfo::self();
+
+    if (RecThreadInfo::self().isTaskThread()) {
+      runTaskOnce(g_logCommonErrors);
       if (now.tv_sec - s_last_ZTC_prune > 60) {
         s_last_ZTC_prune = now.tv_sec;
         static map<DNSName, RecZoneToCache::State> ztcStates;
@@ -1831,6 +1832,9 @@ static void houseKeeping(void*)
           RecZoneToCache::ZoneToCache(ztc.second, ztcStates.at(ztc.first));
         }
       }
+    }
+
+    if (info.isHandler()) {
       if (now.tv_sec - s_last_RC_prune > 5) {
         g_recCache->doPrune(g_maxCacheEntries);
         g_negCache->prune(g_maxCacheEntries / 10);
@@ -2058,7 +2062,7 @@ void* recursorThread()
 
       // Use primes, it avoid not being scheduled in cases where the counter has a regular pattern.
       // We want to call handler thread often, it gets scheduled about 2 times per second
-      if ((threadInfo.isHandler() && s_counter % 11 == 0) || s_counter % 499 == 0) {
+      if (((threadInfo.isHandler() || threadInfo.isTaskThread()) && s_counter % 11 == 0) || s_counter % 499 == 0) {
         MT->makeThread(houseKeeping, 0);
       }
 
index 000af77dd603c6ea2661ada389b6682295e1f9a3..60e1d48e6bb2e439f46588864c13b4d1e311c46e 100644 (file)
  */
 #include "rec-taskqueue.hh"
 #include "taskqueue.hh"
+#include "lock.hh"
 #include "logger.hh"
 #include "stat_t.hh"
 #include "syncres.hh"
 
-static thread_local pdns::TaskQueue t_taskQueue;
+static LockGuarded<pdns::TaskQueue> s_taskQueue;
 static pdns::stat_t s_almost_expired_tasks_pushed;
 static pdns::stat_t s_almost_expired_tasks_run;
 static pdns::stat_t s_almost_expired_tasks_exceptions;
@@ -70,29 +71,29 @@ static void resolve(const struct timeval& now, bool logErrors, const pdns::Resol
 
 void runTaskOnce(bool logErrors)
 {
-  t_taskQueue.runOnce(logErrors);
+  s_taskQueue.lock()->runOnce(logErrors);
 }
 
 void pushAlmostExpiredTask(const DNSName& qname, uint16_t qtype, time_t deadline)
 {
   ++s_almost_expired_tasks_pushed;
   pdns::ResolveTask task{qname, qtype, deadline, true, resolve};
-  t_taskQueue.push(std::move(task));
+  s_taskQueue.lock()->push(std::move(task));
 }
 
 uint64_t getTaskPushes()
 {
-  return broadcastAccFunction<uint64_t>([] { return t_taskQueue.getPushes(); });
+  return s_taskQueue.lock()->getPushes();
 }
 
 uint64_t getTaskExpired()
 {
-  return broadcastAccFunction<uint64_t>([] { return t_taskQueue.getExpired(); });
+  return s_taskQueue.lock()->getExpired();
 }
 
 uint64_t getTaskSize()
 {
-  return broadcastAccFunction<uint64_t>([] { return t_taskQueue.getSize(); });
+  return s_taskQueue.lock()->size();
 }
 
 uint64_t getAlmostExpiredTasksPushed()
index 11be99ef20db42b4deae090566f0f64d14324b57..817bd94e21e248510662e7caeb626b3427eebb45 100644 (file)
@@ -85,19 +85,4 @@ void TaskQueue::runAll(bool logErrors)
   }
 }
 
-uint64_t* TaskQueue::getPushes() const
-{
-  return new uint64_t(d_pushes);
-}
-
-uint64_t* TaskQueue::getExpired() const
-{
-  return new uint64_t(d_expired);
-}
-
-uint64_t* TaskQueue::getSize() const
-{
-  return new uint64_t(size());
-}
-
 } /* namespace pdns */
index 5bd53029b99ba718bd0f416e748b7e815710aff4..3094079ae8c52227fe62e7015e316ccfaffb12ae 100644 (file)
@@ -77,9 +77,16 @@ public:
   ResolveTask pop();
   bool runOnce(bool logErrors); // Run one task if the queue is not empty
   void runAll(bool logErrors);
-  uint64_t* getPushes() const;
-  uint64_t* getExpired() const;
-  uint64_t* getSize() const;
+
+  uint64_t getPushes()
+  {
+    return d_pushes;
+  }
+
+  uint64_t getExpired()
+  {
+    return d_expired;
+  }
 
 private:
   queue_t d_queue;