7 #include "packager/app/libcrypto_threading.h" 9 #include <openssl/thread.h> 13 #include "packager/base/logging.h" 14 #include "packager/base/synchronization/lock.h" 15 #include "packager/base/threading/platform_thread.h" 22 std::unique_ptr<base::Lock[]> global_locks;
24 void LockFunction(
int mode,
int n,
const char* file,
int line) {
25 VLOG(2) <<
"CryptoLock @ " << file <<
":" << line;
26 if (mode & CRYPTO_LOCK)
27 global_locks[n].Acquire();
29 global_locks[n].Release();
32 void ThreadIdFunction(CRYPTO_THREADID*
id) {
33 CRYPTO_THREADID_set_numeric(
34 id, static_cast<unsigned long>(base::PlatformThread::CurrentId()));
39 LibcryptoThreading::LibcryptoThreading() {
40 global_locks.reset(
new base::Lock[CRYPTO_num_locks()]);
41 CRYPTO_THREADID_set_callback(ThreadIdFunction);
42 CRYPTO_set_locking_callback(LockFunction);
45 LibcryptoThreading::~LibcryptoThreading() {
46 CRYPTO_THREADID_set_callback(NULL);
47 CRYPTO_set_locking_callback(NULL);
All the methods that are virtual are virtual for mocking.