]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make the Lua FFI per-thread counters atomic
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 30 Jun 2021 16:26:02 +0000 (18:26 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 30 Jun 2021 16:26:02 +0000 (18:26 +0200)
We should not actually need that since the rules and actions are
either created sequentially at configuration time or via the console
at runtime, which requires holding the global Lua lock.
Still we don't care about performance when creating these objects
so let's just use an atomic counter instead.

pdns/dnsdist-lua-actions.cc
pdns/dnsdistdist/dnsdist-rules.cc
pdns/dnsdistdist/dnsdist-rules.hh

index aadaa3c008af15e8efabb593f12f862b750f279c..9acbf67b1860fa99c6bf65713b64e07b9f85b790 100644 (file)
@@ -549,13 +549,13 @@ private:
     func_t d_func;
     bool d_initialized{false};
   };
-  static uint64_t s_functionsCounter;
+  static std::atomic<uint64_t> s_functionsCounter;
   static thread_local std::map<uint64_t, PerThreadState> t_perThreadStates;
   std::string d_functionCode;
   uint64_t d_functionID;
 };
 
-uint64_t LuaFFIPerThreadAction::s_functionsCounter = 0;
+std::atomic<uint64_t> LuaFFIPerThreadAction::s_functionsCounter = 0;
 thread_local std::map<uint64_t, LuaFFIPerThreadAction::PerThreadState> LuaFFIPerThreadAction::t_perThreadStates;
 
 class LuaFFIResponseAction: public DNSResponseAction
@@ -671,13 +671,13 @@ private:
     bool d_initialized{false};
   };
 
-  static uint64_t s_functionsCounter;
+  static std::atomic<uint64_t> s_functionsCounter;
   static thread_local std::map<uint64_t, PerThreadState> t_perThreadStates;
   std::string d_functionCode;
   uint64_t d_functionID;
 };
 
-uint64_t LuaFFIPerThreadResponseAction::s_functionsCounter = 0;
+std::atomic<uint64_t> LuaFFIPerThreadResponseAction::s_functionsCounter = 0;
 thread_local std::map<uint64_t, LuaFFIPerThreadResponseAction::PerThreadState> LuaFFIPerThreadResponseAction::t_perThreadStates;
 
 thread_local std::default_random_engine SpoofAction::t_randomEngine;
index f1e6eece97d056d74933bdbbcaec8e37089798ea..96666a21436eaf5338c7316419ef18a099b869f5 100644 (file)
@@ -22,5 +22,5 @@
 
 #include "dnsdist-rules.hh"
 
-uint64_t LuaFFIPerThreadRule::s_functionsCounter = 0;
+std::atomic<uint64_t> LuaFFIPerThreadRule::s_functionsCounter = 0;
 thread_local std::map<uint64_t, LuaFFIPerThreadRule::PerThreadState> LuaFFIPerThreadRule::t_perThreadStates;
index 2c3960df1b2f2718622cd8952d2280bd1090e2af..1d70a80845eae9e7f08bc207c090ba68684d89ab 100644 (file)
@@ -1228,7 +1228,7 @@ private:
     bool d_initialized{false};
   };
 
-  static uint64_t s_functionsCounter;
+  static std::atomic<uint64_t> s_functionsCounter;
   static thread_local std::map<uint64_t, PerThreadState> t_perThreadStates;
   std::string d_functionCode;
   uint64_t d_functionID;