Skip to content

Commit

Permalink
Merge pull request #6287
Browse files Browse the repository at this point in the history
a794284 locking: add a quick example of GUARDED_BY (Cory Fields)
2b890dd locking: fix a few small issues uncovered by -Wthread-safety (Cory Fields)
cd27bba locking: teach Clang's -Wthread-safety to cope with our scoped lock macros (Cory Fields)
  • Loading branch information
laanwj committed Jul 23, 2015
2 parents d946e9a + a794284 commit d2464df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,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
Expand Down Expand Up @@ -527,7 +527,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))
Expand Down Expand Up @@ -557,7 +557,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())
Expand Down Expand Up @@ -591,7 +591,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)
Expand Down Expand Up @@ -3649,7 +3649,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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2183,8 +2183,10 @@ void CNode::EndMessage() UNLOCK_FUNCTION(cs_vSend)
Fuzz(GetArg("-fuzzmessagestest", 10));

if (ssSend.size() == 0)
{
LEAVE_CRITICAL_SECTION(cs_vSend);
return;

}
// Set the size
unsigned int nSize = ssSend.size() - CMessageHeader::HEADER_SIZE;
WriteLE32((uint8_t*)&ssSend[CMessageHeader::MESSAGE_SIZE_OFFSET], nSize);
Expand Down
8 changes: 4 additions & 4 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void PrintLockContention(const char* pszName, const char* pszFile, int nLine);

/** Wrapper around boost::unique_lock<Mutex> */
template <typename Mutex>
class CMutexLock
class SCOPED_LOCKABLE CMutexLock
{
private:
boost::unique_lock<Mutex> lock;
Expand Down Expand Up @@ -129,15 +129,15 @@ class CMutexLock
}

public:
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : lock(mutexIn, boost::defer_lock)
{
if (fTry)
TryEnter(pszName, pszFile, nLine);
else
Enter(pszName, pszFile, nLine);
}

CMutexLock(Mutex* pmutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false)
CMutexLock(Mutex* pmutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(pmutexIn)
{
if (!pmutexIn) return;

Expand All @@ -148,7 +148,7 @@ class CMutexLock
Enter(pszName, pszFile, nLine);
}

~CMutexLock()
~CMutexLock() UNLOCK_FUNCTION()
{
if (lock.owns_lock())
LeaveCritical();
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CTranslationInterface translationInterface;

/** Init OpenSSL library multithreading support */
static CCriticalSection** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line)
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
{
if (mode & CRYPTO_LOCK) {
ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
Expand Down
1 change: 0 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ UniValue listaddressgroupings(const UniValue& params, bool fHelp)
addressInfo.push_back(CBitcoinAddress(address).ToString());
addressInfo.push_back(ValueFromAmount(balances[address]));
{
LOCK(pwalletMain->cs_wallet);
if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
}
Expand Down

0 comments on commit d2464df

Please sign in to comment.