From: Remi Gacogne Date: Wed, 30 Jun 2021 16:26:02 +0000 (+0200) Subject: dnsdist: Make the Lua FFI per-thread counters atomic X-Git-Tag: dnsdist-1.7.0-alpha1~88^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5e84ef2bdf1c6b22bf25dd9704e5cc0668cfbf;p=thirdparty%2Fpdns.git dnsdist: Make the Lua FFI per-thread counters atomic 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. --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index aadaa3c008..9acbf67b18 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -549,13 +549,13 @@ private: func_t d_func; bool d_initialized{false}; }; - static uint64_t s_functionsCounter; + static std::atomic s_functionsCounter; static thread_local std::map t_perThreadStates; std::string d_functionCode; uint64_t d_functionID; }; -uint64_t LuaFFIPerThreadAction::s_functionsCounter = 0; +std::atomic LuaFFIPerThreadAction::s_functionsCounter = 0; thread_local std::map LuaFFIPerThreadAction::t_perThreadStates; class LuaFFIResponseAction: public DNSResponseAction @@ -671,13 +671,13 @@ private: bool d_initialized{false}; }; - static uint64_t s_functionsCounter; + static std::atomic s_functionsCounter; static thread_local std::map t_perThreadStates; std::string d_functionCode; uint64_t d_functionID; }; -uint64_t LuaFFIPerThreadResponseAction::s_functionsCounter = 0; +std::atomic LuaFFIPerThreadResponseAction::s_functionsCounter = 0; thread_local std::map LuaFFIPerThreadResponseAction::t_perThreadStates; thread_local std::default_random_engine SpoofAction::t_randomEngine; diff --git a/pdns/dnsdistdist/dnsdist-rules.cc b/pdns/dnsdistdist/dnsdist-rules.cc index f1e6eece97..96666a2143 100644 --- a/pdns/dnsdistdist/dnsdist-rules.cc +++ b/pdns/dnsdistdist/dnsdist-rules.cc @@ -22,5 +22,5 @@ #include "dnsdist-rules.hh" -uint64_t LuaFFIPerThreadRule::s_functionsCounter = 0; +std::atomic LuaFFIPerThreadRule::s_functionsCounter = 0; thread_local std::map LuaFFIPerThreadRule::t_perThreadStates; diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index 2c3960df1b..1d70a80845 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -1228,7 +1228,7 @@ private: bool d_initialized{false}; }; - static uint64_t s_functionsCounter; + static std::atomic s_functionsCounter; static thread_local std::map t_perThreadStates; std::string d_functionCode; uint64_t d_functionID;