summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2024-01-04 21:22:12 +0200
committerTarja Sundqvist <tarja.sundqvist@qt.io>2024-01-04 21:22:12 +0200
commitfc0b6affe244e40366bd624d6e01c62712568eb8 (patch)
treec2ca939bddbf420f39ae570267165da35078bef9
parentc3a7debff7a4c6ddaedb795290180dd99d7ac4be (diff)
parent3e7f8e829be805a2bdffda8732d34c8f9c9f1594 (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.13' into tqtc/lts-5.15-opensourcev5.15.13-lts-lgpl5.15
-rw-r--r--.qmake.conf2
-rw-r--r--src/serialport/qwinoverlappedionotifier.cpp11
2 files changed, 11 insertions, 2 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 0b51738b..33171164 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -2,4 +2,4 @@ load(qt_build_config)
DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST
-MODULE_VERSION = 5.15.12
+MODULE_VERSION = 5.15.13
diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp
index 2090004b..8ec5c1a8 100644
--- a/src/serialport/qwinoverlappedionotifier.cpp
+++ b/src/serialport/qwinoverlappedionotifier.cpp
@@ -396,8 +396,8 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod
Q_Q(QWinOverlappedIoNotifier);
WaitForSingleObject(hResultsMutex, INFINITE);
results.enqueue(IOResult(numberOfBytes, errorCode, overlapped));
- ReleaseMutex(hResultsMutex);
ReleaseSemaphore(hSemaphore, 1, NULL);
+ ReleaseMutex(hResultsMutex);
// Do not send a signal if we didn't process the previous one.
// This is done to prevent soft memory leaks when working in a completely
// synchronous way.
@@ -417,6 +417,15 @@ void QWinOverlappedIoNotifierPrivate::_q_notified()
WaitForSingleObject(hResultsMutex, INFINITE);
QQueue<IOResult> values;
results.swap(values);
+ // Decreasing the semaphore count to keep it in sync with the number
+ // of messages in queue. As ReleaseSemaphore does not accept negative
+ // values, this is sort of a recommended way to go:
+ // https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesemaphore#remarks
+ int numToDecrease = values.size() - 1;
+ while (numToDecrease > 0) {
+ WaitForSingleObject(hSemaphore, 0);
+ --numToDecrease;
+ }
ReleaseMutex(hResultsMutex);
// 'q' can go out of scope if the user decides to close the serial port
// while processing some answer. So we need to guard against that.