@@ -482,6 +482,7 @@ class CAddrMan
482
482
// ! Return the number of (unique) addresses in all tables.
483
483
size_t size () const
484
484
{
485
+ LOCK (cs); // TODO: Cache this in an atomic to avoid this overhead
485
486
return vRandom.size ();
486
487
}
487
488
@@ -501,13 +502,11 @@ class CAddrMan
501
502
// ! Add a single address.
502
503
bool Add (const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0 )
503
504
{
505
+ LOCK (cs);
504
506
bool fRet = false ;
505
- {
506
- LOCK (cs);
507
- Check ();
508
- fRet |= Add_ (addr, source, nTimePenalty);
509
- Check ();
510
- }
507
+ Check ();
508
+ fRet |= Add_ (addr, source, nTimePenalty);
509
+ Check ();
511
510
if (fRet )
512
511
LogPrint (" addrman" , " Added %s from %s: %i tried, %i new\n " , addr.ToStringIPPort (), source.ToString (), nTried, nNew);
513
512
return fRet ;
@@ -516,14 +515,12 @@ class CAddrMan
516
515
// ! Add multiple addresses.
517
516
bool Add (const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0 )
518
517
{
518
+ LOCK (cs);
519
519
int nAdd = 0 ;
520
- {
521
- LOCK (cs);
522
- Check ();
523
- for (std::vector<CAddress>::const_iterator it = vAddr.begin (); it != vAddr.end (); it++)
524
- nAdd += Add_ (*it, source, nTimePenalty) ? 1 : 0 ;
525
- Check ();
526
- }
520
+ Check ();
521
+ for (std::vector<CAddress>::const_iterator it = vAddr.begin (); it != vAddr.end (); it++)
522
+ nAdd += Add_ (*it, source, nTimePenalty) ? 1 : 0 ;
523
+ Check ();
527
524
if (nAdd)
528
525
LogPrint (" addrman" , " Added %i addresses from %s: %i tried, %i new\n " , nAdd, source.ToString (), nTried, nNew);
529
526
return nAdd > 0 ;
0 commit comments