From: Otto Moerbeek Date: Fri, 27 Sep 2019 12:40:24 +0000 (+0200) Subject: bind backend: pthread_mutex_t should be inited and destroyed and not be copied X-Git-Tag: dnsdist-1.4.0-rc3~3^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7fff09acbd57c41b28d6dfba7a55e561167ace1a;p=pdns bind backend: pthread_mutex_t should be inited and destroyed and not be copied To make our live easier, use a native C++ mutex. Fixes #8161 --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 089227154..4322f220f 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -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 +std::mutex LookButDontTouch::s_lock; + BB2DomainInfo::BB2DomainInfo() { d_loaded=false; diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index 7dc8036b4..5256f4832 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -103,22 +104,18 @@ template class LookButDontTouch // : public boost::noncopyable { public: - LookButDontTouch() + LookButDontTouch() { - pthread_mutex_init(&d_lock, 0); - pthread_mutex_init(&d_swaplock, 0); } LookButDontTouch(shared_ptr records) : d_records(records) { - pthread_mutex_init(&d_lock, 0); - pthread_mutex_init(&d_swaplock, 0); } shared_ptr get() { shared_ptr ret; { - Lock l(&d_lock); + std::lock_guard lock(s_lock); ret = d_records; } return ret; @@ -128,22 +125,14 @@ public: { shared_ptr ret; { - Lock l(&d_lock); + std::lock_guard lock(s_lock); ret = d_records; } return ret; } - - void swap(shared_ptr 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 d_records; };