From 7f9bd14f1f698e136d1c5986c61bdc61cf15b5fb Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Tue, 28 Jan 2014 22:45:58 -0200 Subject: [PATCH] openssl's thread id callback is needed for stable operation. intermittent block hash validation errors seen otherwise, most likely due to libtorrent hasher using openssl lib from another thread. --- src/util.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index db0a9f7a..b6a0339b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -96,6 +96,11 @@ void locking_callback(int mode, int i, const char* file, int line) } } +static unsigned long id_callback(void) +{ + return ((unsigned long)pthread_self()); +} + LockedPageManager LockedPageManager::instance; // Init @@ -108,6 +113,7 @@ public: ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*)); for (int i = 0; i < CRYPTO_num_locks(); i++) ppmutexOpenSSL[i] = new CCriticalSection(); + CRYPTO_set_id_callback(id_callback); CRYPTO_set_locking_callback(locking_callback); #ifdef WIN32 @@ -121,6 +127,7 @@ public: ~CInit() { // Shutdown OpenSSL library multithreading support + CRYPTO_set_id_callback(NULL); CRYPTO_set_locking_callback(NULL); for (int i = 0; i < CRYPTO_num_locks(); i++) delete ppmutexOpenSSL[i];