Skip to content

Commit b312cd7

Browse files
Add missing locking annotations
1 parent 600b85b commit b312cd7

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

src/net.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ bool fDiscover = true;
8282
bool fListen = true;
8383
bool fRelayTxes = true;
8484
CCriticalSection cs_mapLocalHost;
85-
std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
86-
static bool vfLimited[NET_MAX] = {};
85+
std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
86+
static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {};
8787
std::string strSubVersion;
8888

8989
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
@@ -874,16 +874,7 @@ const uint256& CNetMessage::GetMessageHash() const
874874
return data_hash;
875875
}
876876

877-
878-
879-
880-
881-
882-
883-
884-
885-
// requires LOCK(cs_vSend)
886-
size_t CConnman::SocketSendData(CNode *pnode) const
877+
size_t CConnman::SocketSendData(CNode *pnode) const EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_vSend)
887878
{
888879
auto it = pnode->vSendMsg.begin();
889880
size_t nSentSize = 0;

src/net.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@ class CConnman
400400

401401
std::vector<ListenSocket> vhListenSocket;
402402
std::atomic<bool> fNetworkActive;
403-
banmap_t setBanned;
403+
banmap_t setBanned GUARDED_BY(cs_setBanned);
404404
CCriticalSection cs_setBanned;
405-
bool setBannedIsDirty;
405+
bool setBannedIsDirty GUARDED_BY(cs_setBanned);
406406
bool fAddressesInitialized;
407407
CAddrMan addrman;
408-
std::deque<std::string> vOneShots;
408+
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
409409
CCriticalSection cs_vOneShots;
410410
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
411411
CCriticalSection cs_vAddedNodes;
@@ -540,7 +540,7 @@ struct LocalServiceInfo {
540540
};
541541

542542
extern CCriticalSection cs_mapLocalHost;
543-
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
543+
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
544544
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
545545

546546
class CNodeStats
@@ -630,23 +630,23 @@ class CNode
630630
public:
631631
// socket
632632
std::atomic<ServiceFlags> nServices;
633-
SOCKET hSocket;
633+
SOCKET hSocket GUARDED_BY(cs_hSocket);
634634
size_t nSendSize; // total size of all vSendMsg entries
635635
size_t nSendOffset; // offset inside the first vSendMsg already sent
636-
uint64_t nSendBytes;
637-
std::deque<std::vector<unsigned char>> vSendMsg;
636+
uint64_t nSendBytes GUARDED_BY(cs_vSend);
637+
std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
638638
CCriticalSection cs_vSend;
639639
CCriticalSection cs_hSocket;
640640
CCriticalSection cs_vRecv;
641641

642642
CCriticalSection cs_vProcessMsg;
643-
std::list<CNetMessage> vProcessMsg;
643+
std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
644644
size_t nProcessQueueSize;
645645

646646
CCriticalSection cs_sendProcessing;
647647

648648
std::deque<CInv> vRecvGetData;
649-
uint64_t nRecvBytes;
649+
uint64_t nRecvBytes GUARDED_BY(cs_vRecv);
650650
std::atomic<int> nRecvVersion;
651651

652652
std::atomic<int64_t> nLastSend;
@@ -662,7 +662,7 @@ class CNode
662662
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
663663
// store the sanitized version in cleanSubVer. The original should be used when dealing with
664664
// the network or wire types and the cleaned string used when displayed or logged.
665-
std::string strSubVer, cleanSubVer;
665+
std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer);
666666
CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
667667
bool fWhitelisted; // This peer can bypass DoS banning.
668668
bool fFeeler; // If true this node is being used as a short lived feeler.
@@ -681,7 +681,7 @@ class CNode
681681
bool fSentAddr;
682682
CSemaphoreGrant grantOutbound;
683683
mutable CCriticalSection cs_filter;
684-
std::unique_ptr<CBloomFilter> pfilter;
684+
std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter);
685685
std::atomic<int> nRefCount;
686686

687687
const uint64_t nKeyedNetGroup;
@@ -690,7 +690,7 @@ class CNode
690690
protected:
691691

692692
mapMsgCmdSize mapSendBytesPerMsgCmd;
693-
mapMsgCmdSize mapRecvBytesPerMsgCmd;
693+
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
694694

695695
public:
696696
uint256 hashContinue;
@@ -701,18 +701,18 @@ class CNode
701701
CRollingBloomFilter addrKnown;
702702
bool fGetAddr;
703703
std::set<uint256> setKnown;
704-
int64_t nNextAddrSend;
705-
int64_t nNextLocalAddrSend;
704+
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing);
705+
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing);
706706

707707
// inventory based relay
708-
CRollingBloomFilter filterInventoryKnown;
708+
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory);
709709
// Set of transaction ids we still have to announce.
710710
// They are sorted by the mempool before relay, so the order is not important.
711711
std::set<uint256> setInventoryTxToSend;
712712
// List of block ids we still have announce.
713713
// There is no final sorting before sending, as they are always sent immediately
714714
// and in the order requested.
715-
std::vector<uint256> vInventoryBlockToSend;
715+
std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
716716
CCriticalSection cs_inventory;
717717
std::set<uint256> setAskFor;
718718
std::multimap<int64_t, CInv> mapAskFor;
@@ -741,7 +741,7 @@ class CNode
741741
// Whether a ping is requested.
742742
std::atomic<bool> fPingQueued;
743743
// Minimum fee rate with which to filter inv's to this node
744-
CAmount minFeeFilter;
744+
CAmount minFeeFilter GUARDED_BY(cs_feeFilter);
745745
CCriticalSection cs_feeFilter;
746746
CAmount lastSentFeeFilter;
747747
int64_t nextSendTimeFeeFilter;
@@ -761,10 +761,10 @@ class CNode
761761
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
762762

763763
mutable CCriticalSection cs_addrName;
764-
std::string addrName;
764+
std::string addrName GUARDED_BY(cs_addrName);
765765

766766
// Our address, as reported by the peer
767-
CService addrLocal;
767+
CService addrLocal GUARDED_BY(cs_addrLocal);
768768
mutable CCriticalSection cs_addrLocal;
769769
public:
770770

src/netbase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#endif
2727

2828
// Settings
29-
static proxyType proxyInfo[NET_MAX];
30-
static proxyType nameProxy;
3129
static CCriticalSection cs_proxyInfos;
30+
static proxyType proxyInfo[NET_MAX] GUARDED_BY(cs_proxyInfos);
31+
static proxyType nameProxy GUARDED_BY(cs_proxyInfos);
3232
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
3333
bool fNameLookup = DEFAULT_NAME_LOOKUP;
3434

0 commit comments

Comments
 (0)