TLS backend OpenSSL: Use function-static variable for symbol loading
Replace a combination of a mutex, atomic variable, and another 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. Task-number: QTBUG-103559 Change-Id: If9af8584e648ddb9ec518498ce035105e52413a2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
aed7b5f370
commit
1c217ba6f7
@ -28,7 +28,6 @@
|
|||||||
#elif QT_CONFIG(library)
|
#elif QT_CONFIG(library)
|
||||||
# include <QtCore/qlibrary.h>
|
# include <QtCore/qlibrary.h>
|
||||||
#endif
|
#endif
|
||||||
#include <QtCore/qmutex.h>
|
|
||||||
#include <QtCore/qdatetime.h>
|
#include <QtCore/qdatetime.h>
|
||||||
#if defined(Q_OS_UNIX)
|
#if defined(Q_OS_UNIX)
|
||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
@ -832,21 +831,9 @@ static LoadedOpenSsl loadOpenSsl()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Q_CONSTINIT static QBasicMutex symbolResolveMutex;
|
|
||||||
Q_CONSTINIT static QBasicAtomicInt symbolsResolved = Q_BASIC_ATOMIC_INITIALIZER(false);
|
|
||||||
Q_CONSTINIT static bool triedToResolveSymbols = false;
|
|
||||||
|
|
||||||
bool q_resolveOpenSslSymbols()
|
bool q_resolveOpenSslSymbols()
|
||||||
{
|
{
|
||||||
if (symbolsResolved.loadAcquire())
|
static bool symbolsResolved = []() {
|
||||||
return true;
|
|
||||||
QMutexLocker locker(&symbolResolveMutex);
|
|
||||||
if (symbolsResolved.loadRelaxed())
|
|
||||||
return true;
|
|
||||||
if (triedToResolveSymbols)
|
|
||||||
return false;
|
|
||||||
triedToResolveSymbols = true;
|
|
||||||
|
|
||||||
LoadedOpenSsl libs = loadOpenSsl();
|
LoadedOpenSsl libs = loadOpenSsl();
|
||||||
if (!libs.ssl || !libs.crypto) {
|
if (!libs.ssl || !libs.crypto) {
|
||||||
qCWarning(lcTlsBackend, "Failed to load libssl/libcrypto.");
|
qCWarning(lcTlsBackend, "Failed to load libssl/libcrypto.");
|
||||||
@ -1235,9 +1222,10 @@ bool q_resolveOpenSslSymbols()
|
|||||||
RESOLVEFUNC(PKCS12_parse)
|
RESOLVEFUNC(PKCS12_parse)
|
||||||
RESOLVEFUNC(d2i_PKCS12_bio)
|
RESOLVEFUNC(d2i_PKCS12_bio)
|
||||||
RESOLVEFUNC(PKCS12_free)
|
RESOLVEFUNC(PKCS12_free)
|
||||||
|
|
||||||
symbolsResolved.storeRelease(true);
|
|
||||||
return true;
|
return true;
|
||||||
|
}();
|
||||||
|
|
||||||
|
return symbolsResolved;
|
||||||
}
|
}
|
||||||
#endif // QT_CONFIG(library)
|
#endif // QT_CONFIG(library)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user