Initial Commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#ifndef UTIL_HTTPCLIENTHELPERS_H
|
||||
#define UTIL_HTTPCLIENTHELPERS_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
|
||||
namespace PresenceDetection {
|
||||
namespace Util {
|
||||
|
||||
static std::vector<boost::shared_ptr<boost::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] = boost::shared_ptr<boost::mutex>(new boost::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
|
||||
Reference in New Issue
Block a user