47 lines
938 B
C++
47 lines
938 B
C++
#ifndef UTIL_HTTPCLIENTHELPERS_H
|
|
#define UTIL_HTTPCLIENTHELPERS_H
|
|
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <vector>
|
|
#include <openssl/crypto.h>
|
|
|
|
|
|
namespace PresenceDetection {
|
|
namespace Util {
|
|
|
|
static std::vector<std::shared_ptr<std::mutex> > g_mutexes;
|
|
|
|
static void LockCallback(int mode, int type, const char* /*file*/, int /*line*/)
|
|
{
|
|
if (mode & CRYPTO_LOCK)
|
|
g_mutexes[type]->lock();
|
|
else
|
|
g_mutexes[type]->unlock();
|
|
}
|
|
|
|
static unsigned long ThreadId(void)
|
|
{
|
|
return (unsigned long)pthread_self();
|
|
}
|
|
|
|
static void InitializeLocks(void)
|
|
{
|
|
g_mutexes.resize(CRYPTO_num_locks());
|
|
for (int i = 0; i < CRYPTO_num_locks(); ++i)
|
|
g_mutexes[i] = std::shared_ptr<std::mutex>(new std::mutex());
|
|
|
|
CRYPTO_set_id_callback(ThreadId);
|
|
CRYPTO_set_locking_callback(LockCallback);
|
|
}
|
|
|
|
static void FreeLocks(void)
|
|
{
|
|
CRYPTO_set_locking_callback(NULL);
|
|
}
|
|
|
|
} // namespace Util
|
|
} // namespace PresenceDetection
|
|
|
|
#endif // UTIL_HTTPCLIENTHELPERS_H
|