Fix AddrMan locking
This commit is contained in:
parent
047ea1052d
commit
dbfaade72a
1 changed files with 10 additions and 13 deletions
|
@ -482,6 +482,7 @@ public:
|
||||||
//! Return the number of (unique) addresses in all tables.
|
//! Return the number of (unique) addresses in all tables.
|
||||||
size_t size() const
|
size_t size() const
|
||||||
{
|
{
|
||||||
|
LOCK(cs); // TODO: Cache this in an atomic to avoid this overhead
|
||||||
return vRandom.size();
|
return vRandom.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,14 +501,12 @@ public:
|
||||||
|
|
||||||
//! Add a single address.
|
//! Add a single address.
|
||||||
bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
|
bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
|
||||||
{
|
|
||||||
bool fRet = false;
|
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
bool fRet = false;
|
||||||
Check();
|
Check();
|
||||||
fRet |= Add_(addr, source, nTimePenalty);
|
fRet |= Add_(addr, source, nTimePenalty);
|
||||||
Check();
|
Check();
|
||||||
}
|
|
||||||
if (fRet)
|
if (fRet)
|
||||||
LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
|
LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
|
||||||
return fRet;
|
return fRet;
|
||||||
|
@ -515,15 +514,13 @@ public:
|
||||||
|
|
||||||
//! Add multiple addresses.
|
//! Add multiple addresses.
|
||||||
bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
|
bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
|
||||||
{
|
|
||||||
int nAdd = 0;
|
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
int nAdd = 0;
|
||||||
Check();
|
Check();
|
||||||
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
|
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
|
||||||
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
|
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
|
||||||
Check();
|
Check();
|
||||||
}
|
|
||||||
if (nAdd)
|
if (nAdd)
|
||||||
LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
|
LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
|
||||||
return nAdd > 0;
|
return nAdd > 0;
|
||||||
|
|
Loading…
Reference in a new issue