]> granicus.if.org Git - pdns/commitdiff
bind backend: pthread_mutex_t should be inited and destroyed and not be copied
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 27 Sep 2019 12:40:24 +0000 (14:40 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 27 Sep 2019 13:04:30 +0000 (15:04 +0200)
To make our live easier, use a native C++ mutex.
Fixes #8161

modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh

index 089227154868469ab6f69983c90513f19472da46..4322f220f23c6e2fa3edbbf18f4d73cb1ed47724 100644 (file)
@@ -80,6 +80,9 @@ pthread_mutex_t Bind2Backend::s_supermaster_config_lock=PTHREAD_MUTEX_INITIALIZE
 pthread_mutex_t Bind2Backend::s_startup_lock=PTHREAD_MUTEX_INITIALIZER;
 string Bind2Backend::s_binddirectory;  
 
+template <typename T>
+std::mutex LookButDontTouch<T>::s_lock;
+
 BB2DomainInfo::BB2DomainInfo()
 {
   d_loaded=false;
index 7dc8036b43cf2f4ab1a47e6e778e695eba8d58b0..5256f4832dc1b9f690c97cf7e123ae2f5492ffb9 100644 (file)
@@ -29,6 +29,7 @@
 #include <pthread.h>
 #include <time.h>
 #include <fstream>
+#include <mutex>
 #include <boost/utility.hpp>
 
 #include <boost/tuple/tuple.hpp>
@@ -103,22 +104,18 @@ template <typename T>
 class LookButDontTouch //  : public boost::noncopyable
 {
 public:
-  LookButDontTouch() 
+  LookButDontTouch()
   {
-    pthread_mutex_init(&d_lock, 0);
-    pthread_mutex_init(&d_swaplock, 0);
   }
   LookButDontTouch(shared_ptr<T> records) : d_records(records)
   {
-    pthread_mutex_init(&d_lock, 0);
-    pthread_mutex_init(&d_swaplock, 0);
   }
 
   shared_ptr<const T> get()
   {
     shared_ptr<const T> ret;
     {
-      Lock l(&d_lock);
+      std::lock_guard<std::mutex> lock(s_lock);
       ret = d_records;
     }
     return ret;
@@ -128,22 +125,14 @@ public:
   {
     shared_ptr<T> ret;
     {
-      Lock l(&d_lock);
+      std::lock_guard<std::mutex> lock(s_lock);
       ret = d_records;
     }
     return ret;
   }
 
-
-  void swap(shared_ptr<T> records)
-  {
-    Lock l(&d_lock);
-    Lock l2(&d_swaplock);
-    d_records.swap(records);
-  }
-  pthread_mutex_t d_lock;
-  pthread_mutex_t d_swaplock;
 private:
+  static std::mutex s_lock;
   shared_ptr<T> d_records;
 };