Fix QWinOverlappedIoNotifier


Commit f3a306a30fc4f40d1c96fee0ed44517fe8b43d76 started processing
the whole input queue in _q_notified() slot. The reads from the input
queue are guarded by the hSemaphore variable, and this approach results
in discrepancy between the hSemaphore value and the amount of messages
in the queue.
As a result, we sometimes could try to read from an empty queue, because
the semaphore still had a non-zero value.

This commit attempts to fix it by manually adjusting the hSemaphore
count in such scenarios, and also reorderding the mutex and semaphore
calls to make sure that the hSemaphore value is not modified from the
QWinOverlapped thread while it is decremented to match the messages
count.

This commit amends f3a306a30fc4f40d1c96fee0ed44517fe8b43d76.

Fixes: QTBUG-108450
Pick-to: 6.4 6.2 5.15
Change-Id: I0c568c37119b83aafd5f98a22703b19f37b4fbc9
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
commitee17a51a12428924adadd16f8c2fe8246d6bcc7f
parente3bb82c12f4cebf70242a17791fc570f5088f37d
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeMon, 12 Dec 2022 14:21:53 +0100