aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cuckoocache.h29
-rw-r--r--src/rpc/server.cpp1
-rw-r--r--src/util.cpp17
3 files changed, 19 insertions, 28 deletions
diff --git a/src/cuckoocache.h b/src/cuckoocache.h
index ff47e9776b..5837549455 100644
--- a/src/cuckoocache.h
+++ b/src/cuckoocache.h
@@ -154,7 +154,7 @@ public:
* @tparam Element should be a movable and copyable type
* @tparam Hash should be a function/callable which takes a template parameter
* hash_select and an Element and extracts a hash from it. Should return
- * high-entropy hashes for `Hash h; h<0>(e) ... h<7>(e)`.
+ * high-entropy uint32_t hashes for `Hash h; h<0>(e) ... h<7>(e)`.
*/
template <typename Element, typename Hash>
class cache
@@ -193,12 +193,6 @@ private:
*/
uint32_t epoch_size;
- /** hash_mask should be set to appropriately mask out a hash such that every
- * masked hash is [0,size), eg, if floor(log2(size)) == 20, then hash_mask
- * should be (1<<20)-1
- */
- uint32_t hash_mask;
-
/** depth_limit determines how many elements insert should try to replace.
* Should be set to log2(n)*/
uint8_t depth_limit;
@@ -217,14 +211,14 @@ private:
*/
inline std::array<uint32_t, 8> compute_hashes(const Element& e) const
{
- return {{hash_function.template operator()<0>(e) & hash_mask,
- hash_function.template operator()<1>(e) & hash_mask,
- hash_function.template operator()<2>(e) & hash_mask,
- hash_function.template operator()<3>(e) & hash_mask,
- hash_function.template operator()<4>(e) & hash_mask,
- hash_function.template operator()<5>(e) & hash_mask,
- hash_function.template operator()<6>(e) & hash_mask,
- hash_function.template operator()<7>(e) & hash_mask}};
+ return {{(uint32_t)((hash_function.template operator()<0>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<1>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<2>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<3>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<4>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<5>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<6>(e) * (uint64_t)size) >> 32),
+ (uint32_t)((hash_function.template operator()<7>(e) * (uint64_t)size) >> 32)}};
}
/* end
@@ -305,7 +299,7 @@ public:
}
/** setup initializes the container to store no more than new_size
- * elements. setup rounds down to a power of two size.
+ * elements.
*
* setup should only be called once.
*
@@ -316,8 +310,7 @@ public:
{
// depth_limit must be at least one otherwise errors can occur.
depth_limit = static_cast<uint8_t>(std::log2(static_cast<float>(std::max((uint32_t)2, new_size))));
- size = 1 << depth_limit;
- hash_mask = size-1;
+ size = std::max<uint32_t>(2, new_size);
table.resize(size);
collection_flags.setup(size);
epoch_flags.resize(size);
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index ef9fecd8fe..141062b3c0 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -322,6 +322,7 @@ void StopRPC()
{
LogPrint(BCLog::RPC, "Stopping RPC\n");
deadlineTimers.clear();
+ DeleteAuthCookie();
g_rpcSignals.Stopped();
}
diff --git a/src/util.cpp b/src/util.cpp
index 766826da49..db45ad1626 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -123,26 +123,24 @@ CTranslationInterface translationInterface;
std::atomic<uint32_t> logCategories(0);
/** Init OpenSSL library multithreading support */
-static CCriticalSection** ppmutexOpenSSL;
+static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
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]);
+ ENTER_CRITICAL_SECTION(ppmutexOpenSSL[i]);
} else {
- LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
+ LEAVE_CRITICAL_SECTION(ppmutexOpenSSL[i]);
}
}
-// Init
+// Singleton for wrapping OpenSSL setup/teardown.
class CInit
{
public:
CInit()
{
// Init OpenSSL library multithreading support
- ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
- for (int i = 0; i < CRYPTO_num_locks(); i++)
- ppmutexOpenSSL[i] = new CCriticalSection();
+ ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]);
CRYPTO_set_locking_callback(locking_callback);
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
@@ -166,9 +164,8 @@ public:
RAND_cleanup();
// Shutdown OpenSSL library multithreading support
CRYPTO_set_locking_callback(NULL);
- for (int i = 0; i < CRYPTO_num_locks(); i++)
- delete ppmutexOpenSSL[i];
- OPENSSL_free(ppmutexOpenSSL);
+ // Clear the set of locks now to maintain symmetry with the constructor.
+ ppmutexOpenSSL.reset();
}
}
instance_of_cinit;