From 60e6a602e625019f4746374f0a06c35ecc6bad46 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 12 Oct 2017 10:13:48 +0200 Subject: [PATCH] Use C++11 thread-safe static initializers in coins.h/coins.cpp Taken from Bitcoin #8173/888483098e60f2a944f1d246bbfec4d14a2975f8 Needed to align code for upcoming per-utxo backports. --- src/coins.cpp | 6 +----- src/coins.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index b7dd293d6..39db7dedf 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -56,11 +56,7 @@ void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; } bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); } CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); } -SaltedTxidHasher::SaltedTxidHasher() -{ - GetRandBytes((unsigned char*)&k0, sizeof(k0)); - GetRandBytes((unsigned char*)&k1, sizeof(k1)); -} +SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits::max())), k1(GetRand(std::numeric_limits::max())) {} CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false), cachedCoinsUsage(0) { } diff --git a/src/coins.h b/src/coins.h index b5b67796a..581079081 100644 --- a/src/coins.h +++ b/src/coins.h @@ -269,7 +269,7 @@ class SaltedTxidHasher { private: /** Salt */ - uint64_t k0, k1; + const uint64_t k0, k1; public: SaltedTxidHasher();