}
}
-int AsyncSSLSocket::sslExDataIndex_ = -1;
-std::mutex AsyncSSLSocket::mutex_;
-
int AsyncSSLSocket::getSSLExDataIndex() {
- if (sslExDataIndex_ < 0) {
- std::lock_guard<std::mutex> g(mutex_);
- if (sslExDataIndex_ < 0) {
- sslExDataIndex_ = SSL_get_ex_new_index(0,
- (void*)"AsyncSSLSocket data index", nullptr, nullptr, nullptr);
- }
- }
- return sslExDataIndex_;
+ static auto index = SSL_get_ex_new_index(
+ 0, (void*)"AsyncSSLSocket data index", nullptr, nullptr, nullptr);
+ return index;
}
AsyncSSLSocket* AsyncSSLSocket::getFromSSL(const SSL *ssl) {
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
bool corked_{false};
// SSL related members.
namespace folly {
bool SSLContext::initialized_ = false;
-std::mutex SSLContext::mutex_;
+
+namespace {
+
+std::mutex& initMutex() {
+ static std::mutex m;
+ return m;
+}
+
+} // anonymous namespace
+
#ifdef OPENSSL_NPN_NEGOTIATED
int SSLContext::sNextProtocolsExDataIndex_ = -1;
#endif
// SSLContext implementation
SSLContext::SSLContext(SSLVersion version) {
{
- std::lock_guard<std::mutex> g(mutex_);
+ std::lock_guard<std::mutex> g(initMutex());
initializeOpenSSLLocked();
}
}
void SSLContext::markInitialized() {
- std::lock_guard<std::mutex> g(mutex_);
+ std::lock_guard<std::mutex> g(initMutex());
initialized_ = true;
}
void SSLContext::initializeOpenSSL() {
- std::lock_guard<std::mutex> g(mutex_);
+ std::lock_guard<std::mutex> g(initMutex());
initializeOpenSSLLocked();
}
}
void SSLContext::cleanupOpenSSL() {
- std::lock_guard<std::mutex> g(mutex_);
+ std::lock_guard<std::mutex> g(initMutex());
cleanupOpenSSLLocked();
}
std::vector<ClientHelloCallback> clientHelloCbs_;
#endif
- static std::mutex mutex_;
static bool initialized_;
#ifdef OPENSSL_NPN_NEGOTIATED