refactor(Core): remove ace_autoptr, cleanup (#3276)

This commit is contained in:
Viste
2020-08-25 13:52:22 +03:00
committed by GitHub
parent 208c257b99
commit a9b90c9a07
7 changed files with 46 additions and 42 deletions

View File

@@ -6,52 +6,44 @@
#include <OpenSSLCrypto.h>
#include <openssl/crypto.h>
#include <ace/Thread_Mutex.h>
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
#include <vector>
#include <ace/Thread.h>
std::vector<ACE_Thread_Mutex*> cryptoLocks;
static void lockingCallback(int mode, int type, const char* /*file*/, int /*line*/)
#include <thread>
#include <mutex>
std::vector<std::mutex*> cryptoLocks;
static void lockingCallback(int mode, int type, char const* /*file*/, int /*line*/)
{
if (mode & CRYPTO_LOCK)
cryptoLocks[type]->acquire();
cryptoLocks[type]->lock();
else
cryptoLocks[type]->release();
cryptoLocks[type]->unlock();
}
static void threadIdCallback(CRYPTO_THREADID * id)
{
(void)id;
/// ACE_thread_t turns out to be a struct under Mac OS.
#ifndef __APPLE__
CRYPTO_THREADID_set_numeric(id, ACE_Thread::self());
#else
CRYPTO_THREADID_set_pointer(id, ACE_Thread::self());
#endif
CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id()));
}
void OpenSSLCrypto::threadsSetup()
{
cryptoLocks.resize(CRYPTO_num_locks());
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
{
cryptoLocks[i] = new ACE_Thread_Mutex();
cryptoLocks[i] = new std::mutex();
}
(void)&threadIdCallback;
CRYPTO_THREADID_set_callback(threadIdCallback);
(void)&lockingCallback;
CRYPTO_set_locking_callback(lockingCallback);
}
void OpenSSLCrypto::threadsCleanup()
{
CRYPTO_set_locking_callback(NULL);
CRYPTO_THREADID_set_callback(NULL);
CRYPTO_set_locking_callback(nullptr);
CRYPTO_THREADID_set_callback(nullptr);
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
{
delete cryptoLocks[i];
}
cryptoLocks.resize(0);
}
}
#endif