diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2023-05-22 19:32:20 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-06-30 07:23:56 -0700 |
| commit | 6679efd2a4cc23de4ed947ef567a799d474e2079 (patch) | |
| tree | f873fb493b518f68994705329b73bd4babb7a278 /src/network/kernel/qnetworkproxy_libproxy.cpp | |
| parent | 5bd58d67c14ac765a2a0abb7d5dbb499ac60f13b (diff) | |
Replace one-shot uses of QSemaphore with QLatch
This commit replaces one-shot synchronization of threads that were using
QSemaphore with QLatch. QSemaphore is efficient on Linux and Windows,
but allocates memory elsewhere. Even on those platforms where we have
futex-like OS support, QSemaphore is heavier than what we really need
here.
All but one uses of QSemaphore in qtbase libraries (I didn't change
examples or tests) were replaced. The remaining use of QSemaphore in
qnetworkproxy_libproxy.cpp is a proper producer-consumer.
Change-Id: Ib5ce7a497e034ebabb2cfffd1761a4fcb2be9a6c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/network/kernel/qnetworkproxy_libproxy.cpp')
| -rw-r--r-- | src/network/kernel/qnetworkproxy_libproxy.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/network/kernel/qnetworkproxy_libproxy.cpp b/src/network/kernel/qnetworkproxy_libproxy.cpp index da1e8fdbd4a..b17d46ea96a 100644 --- a/src/network/kernel/qnetworkproxy_libproxy.cpp +++ b/src/network/kernel/qnetworkproxy_libproxy.cpp @@ -10,6 +10,7 @@ #include <QtCore/QMutex> #include <QtCore/QSemaphore> #include <QtCore/QUrl> +#include <QtCore/private/qlatch_p.h> #include <QtCore/private/qeventdispatcher_unix_p.h> #include <QtCore/private/qthread_p.h> #include <QtCore/qapplicationstatic.h> @@ -61,7 +62,7 @@ private: // we leave the conversion to/from QUrl to the calling thread const char *url; char **proxies; - QSemaphore replyReady; + QLatch replyReady{1}; }; void run() override; @@ -119,7 +120,7 @@ QList<QUrl> QLibProxyWrapper::getProxies(const QUrl &url) requestReady.release(); // wait for the reply - data.replyReady.acquire(); + data.replyReady.wait(); } else { // non-threaded mode data.proxies = px_proxy_factory_get_proxies(factory, data.url); @@ -147,7 +148,7 @@ void QLibProxyWrapper::run() if (isInterruptionRequested()) break; request->proxies = px_proxy_factory_get_proxies(factory, request->url); - request->replyReady.release(); + request->replyReady.countDown(); } px_proxy_factory_free(factory); |
