diff options
| author | Matt Corallo <[email protected]> | 2016-11-25 18:11:25 -0800 |
|---|---|---|
| committer | Matt Corallo <[email protected]> | 2016-11-26 15:42:55 -0800 |
| commit | dbfaade72a9d9c1e503c47f8e12d26b1540a921b (patch) | |
| tree | 9236d5480ab521555e3729446b4f4c57ba243883 /src | |
| parent | Make fImporting an std::atomic (diff) | |
| download | discoin-dbfaade72a9d9c1e503c47f8e12d26b1540a921b.tar.xz discoin-dbfaade72a9d9c1e503c47f8e12d26b1540a921b.zip | |
Fix AddrMan locking
Diffstat (limited to 'src')
| -rw-r--r-- | src/addrman.h | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/addrman.h b/src/addrman.h index cabacbbea..d466eefb8 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -482,6 +482,7 @@ public: //! Return the number of (unique) addresses in all tables. size_t size() const { + LOCK(cs); // TODO: Cache this in an atomic to avoid this overhead return vRandom.size(); } @@ -501,13 +502,11 @@ public: //! Add a single address. bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0) { + LOCK(cs); bool fRet = false; - { - LOCK(cs); - Check(); - fRet |= Add_(addr, source, nTimePenalty); - Check(); - } + Check(); + fRet |= Add_(addr, source, nTimePenalty); + Check(); if (fRet) LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew); return fRet; @@ -516,14 +515,12 @@ public: //! Add multiple addresses. bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0) { + LOCK(cs); int nAdd = 0; - { - LOCK(cs); - Check(); - for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++) - nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0; - Check(); - } + Check(); + for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++) + nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0; + Check(); if (nAdd) LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew); return nAdd > 0; |