]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Guard `registerAllStats()` with an atomic flag instead of a bool 5567/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 1 Aug 2017 08:39:16 +0000 (10:39 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 1 Aug 2017 08:39:16 +0000 (10:39 +0200)
Unlikely as it seems, I just got hit by a race where three threads
were trying to register the stats at the same time, causing my
starting recursor to stay stuck while consuming a lot of CPU.

pdns/rec_channel_rec.cc

index 2d086f1ed426a405248d600698df118106a60688..e79dd250e7850df3019891032a2615d03c7d8aeb 100644 (file)
@@ -775,10 +775,9 @@ extern ResponseStats g_rs;
 
 void registerAllStats()
 {
-  static bool s_init = false;
-  if(s_init)
+  static std::atomic_flag s_init = ATOMIC_FLAG_INIT;
+  if(s_init.test_and_set())
     return;
-  s_init=true;
 
   addGetStat("questions", &g_stats.qcounter);
   addGetStat("ipv6-questions", &g_stats.ipv6qcounter);