2014-05-09 01:23:54 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/libcrypto_threading.h"
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2015-07-24 18:44:52 +00:00
|
|
|
#include <openssl/thread.h>
|
2015-03-21 01:37:12 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
|
|
|
#include "packager/base/synchronization/lock.h"
|
|
|
|
#include "packager/base/threading/platform_thread.h"
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-05-09 01:23:54 +00:00
|
|
|
namespace media {
|
|
|
|
|
2015-03-21 01:37:12 +00:00
|
|
|
namespace {
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2015-03-21 01:37:12 +00:00
|
|
|
scoped_ptr<base::Lock[]> global_locks;
|
|
|
|
|
|
|
|
void LockFunction(int mode, int n, const char* file, int line) {
|
|
|
|
VLOG(2) << "CryptoLock @ " << file << ":" << line;
|
|
|
|
if (mode & CRYPTO_LOCK)
|
|
|
|
global_locks[n].Acquire();
|
|
|
|
else
|
|
|
|
global_locks[n].Release();
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 01:37:12 +00:00
|
|
|
void ThreadIdFunction(CRYPTO_THREADID* id) {
|
|
|
|
CRYPTO_THREADID_set_numeric(
|
|
|
|
id, static_cast<unsigned long>(base::PlatformThread::CurrentId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
LibcryptoThreading::LibcryptoThreading() {
|
|
|
|
global_locks.reset(new base::Lock[CRYPTO_num_locks()]);
|
|
|
|
CRYPTO_THREADID_set_callback(ThreadIdFunction);
|
|
|
|
CRYPTO_set_locking_callback(LockFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
LibcryptoThreading::~LibcryptoThreading() {
|
|
|
|
CRYPTO_THREADID_set_callback(NULL);
|
|
|
|
CRYPTO_set_locking_callback(NULL);
|
|
|
|
global_locks.reset();
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|