QTlsBackendOpenSSL: Use a function-static variable in ensureLibraryLoaded()
Replace a combination of a mutex and a state variable by a function-local variable initialized by lambda. C++17 standard guarantees that the lambda is called only once and that any other callers will waiting for initialization to complete. The mutex that was replaced is also used in ensureCiphersAndCertsLoaded() but that seems to be a false sharing. Task-number: QTBUG-103559 Change-Id: Idb269a24b53cf3812ca9630ab4fc87f99ab16d55 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
1c217ba6f7
commit
216fe24ca1
@ -59,7 +59,6 @@ static void q_loadCiphersForConnection(SSL *connection, QList<QSslCipher> &ciphe
|
||||
}
|
||||
}
|
||||
|
||||
bool QTlsBackendOpenSSL::s_libraryLoaded = false;
|
||||
bool QTlsBackendOpenSSL::s_loadedCiphersAndCerts = false;
|
||||
int QTlsBackendOpenSSL::s_indexForSSLExtraData = -1;
|
||||
|
||||
@ -92,12 +91,10 @@ void QTlsBackendOpenSSL::clearErrorQueue()
|
||||
|
||||
bool QTlsBackendOpenSSL::ensureLibraryLoaded()
|
||||
{
|
||||
if (!q_resolveOpenSslSymbols())
|
||||
return false;
|
||||
static bool libraryLoaded = []() {
|
||||
if (!q_resolveOpenSslSymbols())
|
||||
return false;
|
||||
|
||||
const QMutexLocker locker(qt_opensslInitMutex());
|
||||
|
||||
if (!s_libraryLoaded) {
|
||||
// Initialize OpenSSL.
|
||||
if (q_OPENSSL_init_ssl(0, nullptr) != 1)
|
||||
return false;
|
||||
@ -119,10 +116,10 @@ bool QTlsBackendOpenSSL::ensureLibraryLoaded()
|
||||
return false;
|
||||
}
|
||||
|
||||
s_libraryLoaded = true;
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
|
||||
return true;
|
||||
return libraryLoaded;
|
||||
}
|
||||
|
||||
QString QTlsBackendOpenSSL::backendName() const
|
||||
|
@ -43,7 +43,6 @@ public:
|
||||
|
||||
static bool ensureLibraryLoaded();
|
||||
// Index used in SSL_get_ex_data to get the matching TlsCryptographerOpenSSL:
|
||||
static bool s_libraryLoaded;
|
||||
static bool s_loadedCiphersAndCerts;
|
||||
static int s_indexForSSLExtraData;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user