Commit 60331af0 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by facebook-github-bot-1

folly: io: SSLContext/AsyncSSLSocket: drop global static mutex (siof)

Reviewed By: @yfeldblum

Differential Revision: D2446538
parent 062f90e9
...@@ -607,18 +607,10 @@ void AsyncSSLSocket::timeoutExpired() noexcept { ...@@ -607,18 +607,10 @@ void AsyncSSLSocket::timeoutExpired() noexcept {
} }
} }
int AsyncSSLSocket::sslExDataIndex_ = -1;
std::mutex AsyncSSLSocket::mutex_;
int AsyncSSLSocket::getSSLExDataIndex() { int AsyncSSLSocket::getSSLExDataIndex() {
if (sslExDataIndex_ < 0) { static auto index = SSL_get_ex_new_index(
std::lock_guard<std::mutex> g(mutex_); 0, (void*)"AsyncSSLSocket data index", nullptr, nullptr, nullptr);
if (sslExDataIndex_ < 0) { return index;
sslExDataIndex_ = SSL_get_ex_new_index(0,
(void*)"AsyncSSLSocket data index", nullptr, nullptr, nullptr);
}
}
return sslExDataIndex_;
} }
AsyncSSLSocket* AsyncSSLSocket::getFromSSL(const SSL *ssl) { AsyncSSLSocket* AsyncSSLSocket::getFromSSL(const SSL *ssl) {
......
...@@ -803,8 +803,6 @@ class AsyncSSLSocket : public virtual AsyncSocket { ...@@ -803,8 +803,6 @@ class AsyncSSLSocket : public virtual AsyncSocket {
static void sslInfoCallback(const SSL *ssl, int type, int val); static void sslInfoCallback(const SSL *ssl, int type, int val);
static std::mutex mutex_;
static int sslExDataIndex_;
// Whether we've applied the TCP_CORK option to the socket // Whether we've applied the TCP_CORK option to the socket
bool corked_{false}; bool corked_{false};
// SSL related members. // SSL related members.
......
...@@ -35,7 +35,16 @@ struct CRYPTO_dynlock_value { ...@@ -35,7 +35,16 @@ struct CRYPTO_dynlock_value {
namespace folly { namespace folly {
bool SSLContext::initialized_ = false; bool SSLContext::initialized_ = false;
std::mutex SSLContext::mutex_;
namespace {
std::mutex& initMutex() {
static std::mutex m;
return m;
}
} // anonymous namespace
#ifdef OPENSSL_NPN_NEGOTIATED #ifdef OPENSSL_NPN_NEGOTIATED
int SSLContext::sNextProtocolsExDataIndex_ = -1; int SSLContext::sNextProtocolsExDataIndex_ = -1;
#endif #endif
...@@ -43,7 +52,7 @@ int SSLContext::sNextProtocolsExDataIndex_ = -1; ...@@ -43,7 +52,7 @@ int SSLContext::sNextProtocolsExDataIndex_ = -1;
// SSLContext implementation // SSLContext implementation
SSLContext::SSLContext(SSLVersion version) { SSLContext::SSLContext(SSLVersion version) {
{ {
std::lock_guard<std::mutex> g(mutex_); std::lock_guard<std::mutex> g(initMutex());
initializeOpenSSLLocked(); initializeOpenSSLLocked();
} }
...@@ -679,12 +688,12 @@ void SSLContext::setSSLLockTypes(std::map<int, SSLLockType> inLockTypes) { ...@@ -679,12 +688,12 @@ void SSLContext::setSSLLockTypes(std::map<int, SSLLockType> inLockTypes) {
} }
void SSLContext::markInitialized() { void SSLContext::markInitialized() {
std::lock_guard<std::mutex> g(mutex_); std::lock_guard<std::mutex> g(initMutex());
initialized_ = true; initialized_ = true;
} }
void SSLContext::initializeOpenSSL() { void SSLContext::initializeOpenSSL() {
std::lock_guard<std::mutex> g(mutex_); std::lock_guard<std::mutex> g(initMutex());
initializeOpenSSLLocked(); initializeOpenSSLLocked();
} }
...@@ -715,7 +724,7 @@ void SSLContext::initializeOpenSSLLocked() { ...@@ -715,7 +724,7 @@ void SSLContext::initializeOpenSSLLocked() {
} }
void SSLContext::cleanupOpenSSL() { void SSLContext::cleanupOpenSSL() {
std::lock_guard<std::mutex> g(mutex_); std::lock_guard<std::mutex> g(initMutex());
cleanupOpenSSLLocked(); cleanupOpenSSLLocked();
} }
......
...@@ -431,7 +431,6 @@ class SSLContext { ...@@ -431,7 +431,6 @@ class SSLContext {
std::vector<ClientHelloCallback> clientHelloCbs_; std::vector<ClientHelloCallback> clientHelloCbs_;
#endif #endif
static std::mutex mutex_;
static bool initialized_; static bool initialized_;
#ifdef OPENSSL_NPN_NEGOTIATED #ifdef OPENSSL_NPN_NEGOTIATED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment