diff --git a/src/corelib/io/qwinoverlappedionotifier.cpp b/src/corelib/io/qwinoverlappedionotifier.cpp index c6ce15c2c9..c9de6671f7 100644 --- a/src/corelib/io/qwinoverlappedionotifier.cpp +++ b/src/corelib/io/qwinoverlappedionotifier.cpp @@ -102,7 +102,8 @@ public: OVERLAPPED *waitForAnyNotified(int msecs); void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped); - OVERLAPPED *_q_notified(); + void _q_notified(); + OVERLAPPED *dispatchNextIoResult(); static QWinIoCompletionPort *iocp; static HANDLE iocpInstanceLock; @@ -302,8 +303,7 @@ OVERLAPPED *QWinOverlappedIoNotifierPrivate::waitForAnyNotified(int msecs) const DWORD wfso = WaitForSingleObject(hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs)); switch (wfso) { case WAIT_OBJECT_0: - ReleaseSemaphore(hSemaphore, 1, NULL); - return _q_notified(); + return dispatchNextIoResult(); case WAIT_TIMEOUT: return 0; default: @@ -385,17 +385,20 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod emit q->_q_notify(); } -OVERLAPPED *QWinOverlappedIoNotifierPrivate::_q_notified() +void QWinOverlappedIoNotifierPrivate::_q_notified() +{ + if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) + dispatchNextIoResult(); +} + +OVERLAPPED *QWinOverlappedIoNotifierPrivate::dispatchNextIoResult() { Q_Q(QWinOverlappedIoNotifier); - if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) { - WaitForSingleObject(hResultsMutex, INFINITE); - IOResult ioresult = results.dequeue(); - ReleaseMutex(hResultsMutex); - emit q->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped); - return ioresult.overlapped; - } - return 0; + WaitForSingleObject(hResultsMutex, INFINITE); + IOResult ioresult = results.dequeue(); + ReleaseMutex(hResultsMutex); + emit q->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped); + return ioresult.overlapped; } QT_END_NAMESPACE diff --git a/src/corelib/io/qwinoverlappedionotifier_p.h b/src/corelib/io/qwinoverlappedionotifier_p.h index 863f87353e..41945d6556 100644 --- a/src/corelib/io/qwinoverlappedionotifier_p.h +++ b/src/corelib/io/qwinoverlappedionotifier_p.h @@ -58,7 +58,7 @@ class Q_CORE_EXPORT QWinOverlappedIoNotifier : public QObject Q_OBJECT Q_DISABLE_COPY(QWinOverlappedIoNotifier) Q_DECLARE_PRIVATE(QWinOverlappedIoNotifier) - Q_PRIVATE_SLOT(d_func(), OVERLAPPED *_q_notified()) + Q_PRIVATE_SLOT(d_func(), void _q_notified()) friend class QWinIoCompletionPort; public: QWinOverlappedIoNotifier(QObject *parent = 0);