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.
This commit is contained in:
Miguel Freitas 2014-01-28 22:45:58 -02:00
parent 43e57ad05f
commit 7f9bd14f1f

View File

@ -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; LockedPageManager LockedPageManager::instance;
// Init // Init
@ -108,6 +113,7 @@ public:
ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*)); ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
for (int i = 0; i < CRYPTO_num_locks(); i++) for (int i = 0; i < CRYPTO_num_locks(); i++)
ppmutexOpenSSL[i] = new CCriticalSection(); ppmutexOpenSSL[i] = new CCriticalSection();
CRYPTO_set_id_callback(id_callback);
CRYPTO_set_locking_callback(locking_callback); CRYPTO_set_locking_callback(locking_callback);
#ifdef WIN32 #ifdef WIN32
@ -121,6 +127,7 @@ public:
~CInit() ~CInit()
{ {
// Shutdown OpenSSL library multithreading support // Shutdown OpenSSL library multithreading support
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL); CRYPTO_set_locking_callback(NULL);
for (int i = 0; i < CRYPTO_num_locks(); i++) for (int i = 0; i < CRYPTO_num_locks(); i++)
delete ppmutexOpenSSL[i]; delete ppmutexOpenSSL[i];