locking: add a quick example of GUARDED_BY

This was chosen not because it's necessarily helpful, but because its locking
assumptions were already correct.
This commit is contained in:
Cory Fields 2015-06-16 04:08:26 -04:00 committed by Jack Grigg
parent 5093299af0
commit 72b25b0ffd
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with 7 additions and 7 deletions

View File

@ -79,9 +79,9 @@ struct COrphanTx {
CTransaction tx;
NodeId fromPeer;
};
map<uint256, COrphanTx> mapOrphanTransactions;
map<uint256, set<uint256> > mapOrphanTransactionsByPrev;
void EraseOrphansFor(NodeId peer);
map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);;
map<uint256, set<uint256> > mapOrphanTransactionsByPrev GUARDED_BY(cs_main);;
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/**
* Returns true if there are nRequired or more blocks of minVersion or above
@ -554,7 +554,7 @@ CBlockTreeDB *pblocktree = NULL;
// mapOrphanTransactions
//
bool AddOrphanTx(const CTransaction& tx, NodeId peer)
bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
uint256 hash = tx.GetHash();
if (mapOrphanTransactions.count(hash))
@ -584,7 +584,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer)
return true;
}
void static EraseOrphanTx(uint256 hash)
void static EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find(hash);
if (it == mapOrphanTransactions.end())
@ -618,7 +618,7 @@ void EraseOrphansFor(NodeId peer)
}
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
unsigned int nEvicted = 0;
while (mapOrphanTransactions.size() > nMaxOrphans)
@ -4140,7 +4140,7 @@ string GetWarnings(string strFor)
//
bool static AlreadyHave(const CInv& inv)
bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
switch (inv.type)
{