diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-06 18:39:12 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-09 01:59:46 +0200 |
commit | f8dcd5ca6f55ad49807cf7491c1f153f6158400e (patch) | |
tree | 6049e300099aa5f509e408acfff0236367b4a26e /src/keystore.cpp | |
parent | 138d08c5315c45b3dd08184c4eeb77ee3e47ef0a (diff) |
Use scoped locks instead of CRITICAL_BLOCK
Diffstat (limited to 'src/keystore.cpp')
-rw-r--r-- | src/keystore.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/keystore.cpp b/src/keystore.cpp index 23f9e32fa2..7b46f6b07a 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<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!SetCrypted()) return false; @@ -135,8 +141,8 @@ bool CCryptoKeyStore::AddCryptedKey(const std::vector<unsigned char> &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<unsigned char>& 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<unsi bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) { - CRITICAL_BLOCK(cs_KeyStore) { + LOCK(cs_KeyStore); if (!mapCryptedKeys.empty() || IsCrypted()) return false; |