7 #include "packager/app/libcrypto_threading.h"
9 #include <openssl/thread.h>
13 #include "packager/base/logging.h"
14 #include "packager/base/memory/scoped_ptr.h"
15 #include "packager/base/synchronization/lock.h"
16 #include "packager/base/threading/platform_thread.h"
18 namespace edash_packager {
23 scoped_ptr<base::Lock[]> global_locks;
25 void LockFunction(
int mode,
int n,
const char* file,
int line) {
26 VLOG(2) <<
"CryptoLock @ " << file <<
":" << line;
27 if (mode & CRYPTO_LOCK)
28 global_locks[n].Acquire();
30 global_locks[n].Release();
33 void ThreadIdFunction(CRYPTO_THREADID*
id) {
34 CRYPTO_THREADID_set_numeric(
35 id, static_cast<unsigned long>(base::PlatformThread::CurrentId()));
40 LibcryptoThreading::LibcryptoThreading() {
41 global_locks.reset(
new base::Lock[CRYPTO_num_locks()]);
42 CRYPTO_THREADID_set_callback(ThreadIdFunction);
43 CRYPTO_set_locking_callback(LockFunction);
46 LibcryptoThreading::~LibcryptoThreading() {
47 CRYPTO_THREADID_set_callback(NULL);
48 CRYPTO_set_locking_callback(NULL);