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/corelib/kernel/qmetaobject.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/corelib/kernel/qmetaobject.cpp')
| -rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 795cc531114..b48922daeab 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -17,7 +17,7 @@ #include <qthread.h> #include "private/qthread_p.h" #if QT_CONFIG(thread) -#include <qsemaphore.h> +#include "private/qlatch_p.h" #endif // for normalizeTypeInternal @@ -1748,9 +1748,9 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase * if (receiverInSameThread) qWarning("QMetaObject::invokeMethod: Dead lock detected"); - QSemaphore semaphore; - QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, argv, &semaphore)); - semaphore.acquire(); + QLatch latch(1); + QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, argv, &latch)); + latch.wait(); #endif // QT_CONFIG(thread) } else { qWarning("QMetaObject::invokeMethod: Unknown connection type"); @@ -2922,10 +2922,10 @@ auto QMetaMethodInvoker::invokeImpl(QMetaMethod self, void *target, return InvokeFailReason::DeadLockDetected; } - QSemaphore semaphore; + QLatch latch(1); QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction, - nullptr, -1, param, &semaphore)); - semaphore.acquire(); + nullptr, -1, param, &latch)); + latch.wait(); #endif // QT_CONFIG(thread) } return {}; |
