Browse Source

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.
0.13
Cory Fields 10 years ago
parent
commit
a794284e61
  1. 14
      src/main.cpp

14
src/main.cpp

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

Loading…
Cancel
Save