From f8dcd5ca6f55ad49807cf7491c1f153f6158400e Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 6 Apr 2012 18:39:12 +0200 Subject: Use scoped locks instead of CRITICAL_BLOCK --- src/keystore.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/keystore.cpp') diff --git a/src/keystore.cpp b/src/keystore.cpp index 23f9e32fa..7b46f6b07 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -21,31 +21,37 @@ bool CBasicKeyStore::AddKey(const CKey& key) { bool fCompressed = false; CSecret secret = key.GetSecret(fCompressed); - CRITICAL_BLOCK(cs_KeyStore) + { + LOCK(cs_KeyStore); mapKeys[CBitcoinAddress(key.GetPubKey())] = make_pair(secret, fCompressed); + } return true; } bool CBasicKeyStore::AddCScript(const CScript& redeemScript) { - CRITICAL_BLOCK(cs_KeyStore) + { + LOCK(cs_KeyStore); mapScripts[Hash160(redeemScript)] = redeemScript; + } return true; } bool CBasicKeyStore::HaveCScript(const uint160& hash) const { bool result; - CRITICAL_BLOCK(cs_KeyStore) + { + LOCK(cs_KeyStore); result = (mapScripts.count(hash) > 0); + } return result; } bool CBasicKeyStore::GetCScript(const uint160 &hash, CScript& redeemScriptOut) const { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); ScriptMap::const_iterator mi = mapScripts.find(hash); if (mi != mapScripts.end()) { @@ -58,8 +64,8 @@ bool CBasicKeyStore::GetCScript(const uint160 &hash, CScript& redeemScriptOut) c bool CCryptoKeyStore::SetCrypted() { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (fUseCrypto) return true; if (!mapKeys.empty()) @@ -71,8 +77,8 @@ bool CCryptoKeyStore::SetCrypted() bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!SetCrypted()) return false; @@ -100,8 +106,8 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) bool CCryptoKeyStore::AddKey(const CKey& key) { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!IsCrypted()) return CBasicKeyStore::AddKey(key); @@ -123,8 +129,8 @@ bool CCryptoKeyStore::AddKey(const CKey& key) bool CCryptoKeyStore::AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!SetCrypted()) return false; @@ -135,8 +141,8 @@ bool CCryptoKeyStore::AddCryptedKey(const std::vector &vchPubKey, bool CCryptoKeyStore::GetKey(const CBitcoinAddress &address, CKey& keyOut) const { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!IsCrypted()) return CBasicKeyStore::GetKey(address, keyOut); @@ -160,8 +166,8 @@ bool CCryptoKeyStore::GetKey(const CBitcoinAddress &address, CKey& keyOut) const bool CCryptoKeyStore::GetPubKey(const CBitcoinAddress &address, std::vector& vchPubKeyOut) const { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!IsCrypted()) return CKeyStore::GetPubKey(address, vchPubKeyOut); @@ -177,8 +183,8 @@ bool CCryptoKeyStore::GetPubKey(const CBitcoinAddress &address, std::vector