summaryrefslogtreecommitdiff
path: root/src/serialport/qwinoverlappedionotifier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialport/qwinoverlappedionotifier.cpp')
-rw-r--r--src/serialport/qwinoverlappedionotifier.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp
index 615dacc..233ee69 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;
};
@@ -395,14 +396,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()