Replace ACE thread/mutex in OpenSSLCrypto

This commit is contained in:
leak
2014-06-30 16:28:55 +02:00
parent eb36acd152
commit 9588c1d92b
2 changed files with 9 additions and 13 deletions

View File

@@ -27,6 +27,7 @@
#include "Timer.h"
#include <ace/Singleton.h>
#include <ace/Atomic_Op.h>
#include <ace/Null_Mutex.h>
#include "SharedDefines.h"
#include "QueryResult.h"
#include "Callback.h"

View File

@@ -17,28 +17,23 @@
#include <OpenSSLCrypto.h>
#include <openssl/crypto.h>
#include <ace/Thread_Mutex.h>
#include <vector>
#include <ace/Thread.h>
#include <thread>
#include <mutex>
std::vector<ACE_Thread_Mutex*> cryptoLocks;
std::vector<std::mutex*> cryptoLocks;
static void lockingCallback(int mode, int type, const char* /*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)
{
/// 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::this_thread::get_id().hash());
}
void OpenSSLCrypto::threadsSetup()
@@ -46,7 +41,7 @@ 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;
}
CRYPTO_THREADID_set_callback(threadIdCallback);
CRYPTO_set_locking_callback(lockingCallback);
@@ -61,4 +56,4 @@ void OpenSSLCrypto::threadsCleanup()
delete cryptoLocks[i];
}
cryptoLocks.resize(0);
}
}