diff options
Diffstat (limited to 'src/corelib/kernel/qwineventnotifier.cpp')
-rw-r--r-- | src/corelib/kernel/qwineventnotifier.cpp | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/src/corelib/kernel/qwineventnotifier.cpp b/src/corelib/kernel/qwineventnotifier.cpp index 0808374a6a..24de491326 100644 --- a/src/corelib/kernel/qwineventnotifier.cpp +++ b/src/corelib/kernel/qwineventnotifier.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include "qwineventnotifier.h" +#include "qwineventnotifier_p.h" #ifdef Q_OS_WINRT #include "qeventdispatcher_winrt_p.h" @@ -50,19 +50,6 @@ QT_BEGIN_NAMESPACE -class QWinEventNotifierPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QWinEventNotifier) -public: - QWinEventNotifierPrivate() - : handleToEvent(0), enabled(false) {} - QWinEventNotifierPrivate(HANDLE h, bool e) - : handleToEvent(h), enabled(e) {} - - HANDLE handleToEvent; - bool enabled; -}; - /*! \class QWinEventNotifier \inmodule QtCore @@ -170,6 +157,7 @@ void QWinEventNotifier::setHandle(HANDLE hEvent) Q_D(QWinEventNotifier); setEnabled(false); d->handleToEvent = hEvent; + d->signaledCount = 0; } /*! @@ -211,8 +199,11 @@ void QWinEventNotifier::setEnabled(bool enable) d->enabled = enable; QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher.load(); - if (!eventDispatcher) // perhaps application is shutting down + if (!eventDispatcher) { // perhaps application is shutting down + if (!enable && d->waitHandle != nullptr) + d->unregisterWaitObject(); return; + } if (Q_UNLIKELY(thread() != QThread::currentThread())) { qWarning("QWinEventNotifier: Event notifiers cannot be enabled or disabled from another thread"); return; @@ -246,4 +237,50 @@ bool QWinEventNotifier::event(QEvent * e) return false; } +#if defined(Q_OS_WINRT) + +bool QWinEventNotifierPrivate::registerWaitObject() +{ + Q_UNIMPLEMENTED(); + return false; +} + +void QWinEventNotifierPrivate::unregisterWaitObject() +{ + Q_UNIMPLEMENTED(); +} + +#else // defined(Q_OS_WINRT) + +static void CALLBACK wfsoCallback(void *context, BOOLEAN /*ignore*/) +{ + QWinEventNotifierPrivate *nd = reinterpret_cast<QWinEventNotifierPrivate *>(context); + QAbstractEventDispatcher *eventDispatcher = nd->threadData->eventDispatcher.load(); + QEventDispatcherWin32Private *edp = QEventDispatcherWin32Private::get( + static_cast<QEventDispatcherWin32 *>(eventDispatcher)); + ++nd->signaledCount; + SetEvent(edp->winEventNotifierActivatedEvent); +} + +bool QWinEventNotifierPrivate::registerWaitObject() +{ + if (RegisterWaitForSingleObject(&waitHandle, handleToEvent, wfsoCallback, this, + INFINITE, WT_EXECUTEONLYONCE) == 0) { + qErrnoWarning("QWinEventNotifier: RegisterWaitForSingleObject failed."); + return false; + } + return true; +} + +void QWinEventNotifierPrivate::unregisterWaitObject() +{ + // Unregister the wait handle and wait for pending callbacks to finish. + if (UnregisterWaitEx(waitHandle, INVALID_HANDLE_VALUE)) + waitHandle = NULL; + else + qErrnoWarning("QWinEventNotifier: UnregisterWaitEx failed."); +} + +#endif // !defined(Q_OS_WINRT) + QT_END_NAMESPACE |