From: Otto Date: Wed, 27 Jan 2021 13:06:08 +0000 (+0100) Subject: use std::call_once(), it avoids having to think about memory barriers for flags X-Git-Tag: dnsdist-1.6.0-alpha2~47^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04f7481f3441b34b35ba231de5e62f9b06deaf42;p=thirdparty%2Fpdns.git use std::call_once(), it avoids having to think about memory barriers for flags --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 72192b2b90..8bdfbfaab2 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1039,17 +1039,8 @@ static uint64_t doGetMallocated() extern ResponseStats g_rs; -void registerAllStats() +static void registerAllStats1() { - static std::mutex s_lock; - static bool s_inited = false; - - std::lock_guard lock(s_lock); - - if (s_inited) { - return; - } - addGetStat("questions", &g_stats.qcounter); addGetStat("ipv6-questions", &g_stats.ipv6qcounter); addGetStat("tcp-questions", &g_stats.tcpqcounter); @@ -1252,8 +1243,12 @@ void registerAllStats() const std::string name = "ecs-v6-response-bits-" + std::to_string(idx + 1); addGetStat(name, &(SyncRes::s_ecsResponsesBySubnetSize6.at(idx))); } - - s_inited = true; +} + +void registerAllStats() +{ + static std::once_flag s_once; + std::call_once(s_once, registerAllStats1); } void doExitGeneric(bool nicely)