Line 0
Link Here
|
|
|
1 |
------------------------------------------------------------------------------------------ |
2 |
bind backend: pthread_mutex_t should be inited and destroyed and not be copied #8350 |
3 |
|
4 |
To make our live easier, use a native C++ mutex. |
5 |
Fixes #8161 |
6 |
|
7 |
https://github.com/PowerDNS/pdns/pull/8350 |
8 |
------------------------------------------------------------------------------------------ |
9 |
--- modules/bindbackend/bindbackend2.cc.orig 2019-11-29 15:11:44 UTC |
10 |
+++ modules/bindbackend/bindbackend2.cc |
11 |
@@ -80,6 +80,9 @@ pthread_mutex_t Bind2Backend::s_supermaster_config_loc |
12 |
pthread_mutex_t Bind2Backend::s_startup_lock=PTHREAD_MUTEX_INITIALIZER; |
13 |
string Bind2Backend::s_binddirectory; |
14 |
|
15 |
+template <typename T> |
16 |
+std::mutex LookButDontTouch<T>::s_lock; |
17 |
+ |
18 |
BB2DomainInfo::BB2DomainInfo() |
19 |
{ |
20 |
d_loaded=false; |
21 |
--- modules/bindbackend/bindbackend2.hh.orig 2019-11-29 15:11:44 UTC |
22 |
+++ modules/bindbackend/bindbackend2.hh |
23 |
@@ -29,6 +29,7 @@ |
24 |
#include <pthread.h> |
25 |
#include <time.h> |
26 |
#include <fstream> |
27 |
+#include <mutex> |
28 |
#include <boost/utility.hpp> |
29 |
|
30 |
#include <boost/tuple/tuple.hpp> |
31 |
@@ -103,22 +104,18 @@ template <typename T> |
32 |
class LookButDontTouch // : public boost::noncopyable |
33 |
{ |
34 |
public: |
35 |
- LookButDontTouch() |
36 |
+ LookButDontTouch() |
37 |
{ |
38 |
- pthread_mutex_init(&d_lock, 0); |
39 |
- pthread_mutex_init(&d_swaplock, 0); |
40 |
} |
41 |
LookButDontTouch(shared_ptr<T> records) : d_records(records) |
42 |
{ |
43 |
- pthread_mutex_init(&d_lock, 0); |
44 |
- pthread_mutex_init(&d_swaplock, 0); |
45 |
} |
46 |
|
47 |
shared_ptr<const T> get() |
48 |
{ |
49 |
shared_ptr<const T> ret; |
50 |
{ |
51 |
- Lock l(&d_lock); |
52 |
+ std::lock_guard<std::mutex> lock(s_lock); |
53 |
ret = d_records; |
54 |
} |
55 |
return ret; |
56 |
@@ -128,22 +125,14 @@ class LookButDontTouch // : public boost::noncopyable |
57 |
{ |
58 |
shared_ptr<T> ret; |
59 |
{ |
60 |
- Lock l(&d_lock); |
61 |
+ std::lock_guard<std::mutex> lock(s_lock); |
62 |
ret = d_records; |
63 |
} |
64 |
return ret; |
65 |
} |
66 |
|
67 |
- |
68 |
- void swap(shared_ptr<T> records) |
69 |
- { |
70 |
- Lock l(&d_lock); |
71 |
- Lock l2(&d_swaplock); |
72 |
- d_records.swap(records); |
73 |
- } |
74 |
- pthread_mutex_t d_lock; |
75 |
- pthread_mutex_t d_swaplock; |
76 |
private: |
77 |
+ static std::mutex s_lock; |
78 |
shared_ptr<T> d_records; |
79 |
}; |
80 |
|