Remove superfluous ReleaseSemaphore/WFSO calls

Factor out the dispatching of IO results into a separate function.
Do not increment the semaphore count in waitForAnyNotified just to
decrement it again in _q_notified.

Change-Id: I7d4a04b679bb152ab3a5025513f885aee276d086
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Joerg Bornemann 2015-12-18 16:10:13 +01:00
parent 55eaf11bb7
commit 7cde1c029e
2 changed files with 16 additions and 13 deletions

View File

@ -102,7 +102,8 @@ public:
OVERLAPPED *waitForAnyNotified(int msecs); OVERLAPPED *waitForAnyNotified(int msecs);
void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped); void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped);
OVERLAPPED *_q_notified(); void _q_notified();
OVERLAPPED *dispatchNextIoResult();
static QWinIoCompletionPort *iocp; static QWinIoCompletionPort *iocp;
static HANDLE iocpInstanceLock; static HANDLE iocpInstanceLock;
@ -302,8 +303,7 @@ OVERLAPPED *QWinOverlappedIoNotifierPrivate::waitForAnyNotified(int msecs)
const DWORD wfso = WaitForSingleObject(hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs)); const DWORD wfso = WaitForSingleObject(hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs));
switch (wfso) { switch (wfso) {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
ReleaseSemaphore(hSemaphore, 1, NULL); return dispatchNextIoResult();
return _q_notified();
case WAIT_TIMEOUT: case WAIT_TIMEOUT:
return 0; return 0;
default: default:
@ -385,17 +385,20 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod
emit q->_q_notify(); 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); Q_Q(QWinOverlappedIoNotifier);
if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) { WaitForSingleObject(hResultsMutex, INFINITE);
WaitForSingleObject(hResultsMutex, INFINITE); IOResult ioresult = results.dequeue();
IOResult ioresult = results.dequeue(); ReleaseMutex(hResultsMutex);
ReleaseMutex(hResultsMutex); emit q->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped);
emit q->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped); return ioresult.overlapped;
return ioresult.overlapped;
}
return 0;
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -58,7 +58,7 @@ class Q_CORE_EXPORT QWinOverlappedIoNotifier : public QObject
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QWinOverlappedIoNotifier) Q_DISABLE_COPY(QWinOverlappedIoNotifier)
Q_DECLARE_PRIVATE(QWinOverlappedIoNotifier) Q_DECLARE_PRIVATE(QWinOverlappedIoNotifier)
Q_PRIVATE_SLOT(d_func(), OVERLAPPED *_q_notified()) Q_PRIVATE_SLOT(d_func(), void _q_notified())
friend class QWinIoCompletionPort; friend class QWinIoCompletionPort;
public: public:
QWinOverlappedIoNotifier(QObject *parent = 0); QWinOverlappedIoNotifier(QObject *parent = 0);