refactor: Replace RecursiveMutex with Mutex in netbase.cpp

This commit is contained in:
Hennadii Stepanov 2020-06-06 17:19:52 +03:00
parent b1b1739944
commit 78c8f4fe11
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -28,9 +28,9 @@
#endif #endif
// Settings // Settings
static RecursiveMutex cs_proxyInfos; static Mutex g_proxyinfo_mutex;
static proxyType proxyInfo[NET_MAX] GUARDED_BY(cs_proxyInfos); static proxyType proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
static proxyType nameProxy GUARDED_BY(cs_proxyInfos); static proxyType nameProxy GUARDED_BY(g_proxyinfo_mutex);
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
bool fNameLookup = DEFAULT_NAME_LOOKUP; bool fNameLookup = DEFAULT_NAME_LOOKUP;
@ -711,14 +711,14 @@ bool SetProxy(enum Network net, const proxyType &addrProxy) {
assert(net >= 0 && net < NET_MAX); assert(net >= 0 && net < NET_MAX);
if (!addrProxy.IsValid()) if (!addrProxy.IsValid())
return false; return false;
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
proxyInfo[net] = addrProxy; proxyInfo[net] = addrProxy;
return true; return true;
} }
bool GetProxy(enum Network net, proxyType &proxyInfoOut) { bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
assert(net >= 0 && net < NET_MAX); assert(net >= 0 && net < NET_MAX);
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
if (!proxyInfo[net].IsValid()) if (!proxyInfo[net].IsValid())
return false; return false;
proxyInfoOut = proxyInfo[net]; proxyInfoOut = proxyInfo[net];
@ -744,13 +744,13 @@ bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
bool SetNameProxy(const proxyType &addrProxy) { bool SetNameProxy(const proxyType &addrProxy) {
if (!addrProxy.IsValid()) if (!addrProxy.IsValid())
return false; return false;
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
nameProxy = addrProxy; nameProxy = addrProxy;
return true; return true;
} }
bool GetNameProxy(proxyType &nameProxyOut) { bool GetNameProxy(proxyType &nameProxyOut) {
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
if(!nameProxy.IsValid()) if(!nameProxy.IsValid())
return false; return false;
nameProxyOut = nameProxy; nameProxyOut = nameProxy;
@ -758,12 +758,12 @@ bool GetNameProxy(proxyType &nameProxyOut) {
} }
bool HaveNameProxy() { bool HaveNameProxy() {
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
return nameProxy.IsValid(); return nameProxy.IsValid();
} }
bool IsProxy(const CNetAddr &addr) { bool IsProxy(const CNetAddr &addr) {
LOCK(cs_proxyInfos); LOCK(g_proxyinfo_mutex);
for (int i = 0; i < NET_MAX; i++) { for (int i = 0; i < NET_MAX; i++) {
if (addr == static_cast<CNetAddr>(proxyInfo[i].proxy)) if (addr == static_cast<CNetAddr>(proxyInfo[i].proxy))
return true; return true;