diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2022-06-02 17:20:44 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2022-06-13 09:55:38 +0200 |
commit | d2b96260035f452e43011ddaec9dbdbea3ec9e09 (patch) | |
tree | 53ee7d73f2604b7ed39f5340e7e62a4877d0ddd1 /src | |
parent | 3392df4c38248581f431a1ace3a835cb5da8c13b (diff) |
Revert "Revert "Emit _q_notify only if there's no notification pending""
This reverts commit f6b43c36b3839dae54308a6437bbdd99ae9a44de.
Part of chain revert to go back to QWinOverlappedIoNotifier.
Task-number: QTBUG-101444
Change-Id: I393f741a627de91302689fb3f45d0082864c35df
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/serialport/qwinoverlappedionotifier.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp index 09ac7a94..4cde746c 100644 --- a/src/serialport/qwinoverlappedionotifier.cpp +++ b/src/serialport/qwinoverlappedionotifier.cpp @@ -129,6 +129,7 @@ public: HANDLE hSemaphore = nullptr; HANDLE hResultsMutex = nullptr; QAtomicInt waiting; + QAtomicInt pendingNotifications; QQueue<IOResult> results; }; @@ -397,14 +398,17 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod results.enqueue(IOResult(numberOfBytes, errorCode, overlapped)); ReleaseMutex(hResultsMutex); ReleaseSemaphore(hSemaphore, 1, NULL); - if (!waiting) + if (!waiting && pendingNotifications-- == 0) emit q->_q_notify(); } void QWinOverlappedIoNotifierPrivate::_q_notified() { - if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) - dispatchNextIoResult(); + int n = pendingNotifications.fetchAndStoreAcquire(0); + while (--n >= 0) { + if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) + dispatchNextIoResult(); + } } OVERLAPPED *QWinOverlappedIoNotifierPrivate::dispatchNextIoResult() |