Skip to content

Commit 5ef1d0b

Browse files
committed
Add thread safety annotations to CAddrMan public functions
1 parent b138973 commit 5ef1d0b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/addrman.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class CAddrMan
231231
*/
232232
template <typename Stream>
233233
void Serialize(Stream& s_) const
234+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
234235
{
235236
LOCK(cs);
236237

@@ -296,6 +297,7 @@ class CAddrMan
296297

297298
template <typename Stream>
298299
void Unserialize(Stream& s_)
300+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
299301
{
300302
LOCK(cs);
301303

@@ -452,6 +454,7 @@ class CAddrMan
452454
}
453455

454456
void Clear()
457+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
455458
{
456459
LOCK(cs);
457460
std::vector<int>().swap(vRandom);
@@ -487,13 +490,15 @@ class CAddrMan
487490

488491
//! Return the number of (unique) addresses in all tables.
489492
size_t size() const
493+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
490494
{
491495
LOCK(cs); // TODO: Cache this in an atomic to avoid this overhead
492496
return vRandom.size();
493497
}
494498

495499
//! Add a single address.
496500
bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
501+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
497502
{
498503
LOCK(cs);
499504
bool fRet = false;
@@ -508,6 +513,7 @@ class CAddrMan
508513

509514
//! Add multiple addresses.
510515
bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
516+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
511517
{
512518
LOCK(cs);
513519
int nAdd = 0;
@@ -523,6 +529,7 @@ class CAddrMan
523529

524530
//! Mark an entry as accessible.
525531
void Good(const CService &addr, bool test_before_evict = true, int64_t nTime = GetAdjustedTime())
532+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
526533
{
527534
LOCK(cs);
528535
Check();
@@ -532,6 +539,7 @@ class CAddrMan
532539

533540
//! Mark an entry as connection attempted to.
534541
void Attempt(const CService &addr, bool fCountFailure, int64_t nTime = GetAdjustedTime())
542+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
535543
{
536544
LOCK(cs);
537545
Check();
@@ -541,6 +549,7 @@ class CAddrMan
541549

542550
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
543551
void ResolveCollisions()
552+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
544553
{
545554
LOCK(cs);
546555
Check();
@@ -550,6 +559,7 @@ class CAddrMan
550559

551560
//! Randomly select an address in tried that another address is attempting to evict.
552561
CAddrInfo SelectTriedCollision()
562+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
553563
{
554564
LOCK(cs);
555565
Check();
@@ -562,6 +572,7 @@ class CAddrMan
562572
* Choose an address to connect to.
563573
*/
564574
CAddrInfo Select(bool newOnly = false)
575+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
565576
{
566577
LOCK(cs);
567578
Check();
@@ -578,6 +589,7 @@ class CAddrMan
578589
* @param[in] network Select only addresses of this network (nullopt = all).
579590
*/
580591
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network)
592+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
581593
{
582594
LOCK(cs);
583595
Check();
@@ -589,6 +601,7 @@ class CAddrMan
589601

590602
//! Outer function for Connected_()
591603
void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
604+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
592605
{
593606
LOCK(cs);
594607
Check();
@@ -597,6 +610,7 @@ class CAddrMan
597610
}
598611

599612
void SetServices(const CService &addr, ServiceFlags nServices)
613+
EXCLUSIVE_LOCKS_REQUIRED(!cs)
600614
{
601615
LOCK(cs);
602616
Check();

0 commit comments

Comments
 (0)