WinRT: Don't use the native thread handle for waiting

There is no guarantee that the handle from std::thread will be valid
when a wait is made. Instead, simply use an elapsed timer and check
if the thread is finished. This prevents an exception from being thrown
when a bad handle is encountered.

Task-number: QTBUG-31397
Change-Id: Ie2a7e6cbfbb27bf1baff779322670d85e92e10dd
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
This commit is contained in:
Andrew Knight 2014-04-10 17:12:20 +03:00 committed by The Qt Project
parent 839c54e070
commit 8b0fd78caa

View File

@ -63,6 +63,7 @@
#include <qt_windows.h> #include <qt_windows.h>
#ifdef Q_OS_WINRT #ifdef Q_OS_WINRT
#include <qelapsedtimer.h>
#include <thread> #include <thread>
#endif #endif
@ -680,21 +681,11 @@ bool QThread::wait(unsigned long time)
break; break;
} }
#else // !Q_OS_WINRT #else // !Q_OS_WINRT
if (d->handle->joinable()) { if (!d->finished) {
HANDLE handle = d->handle->native_handle(); QElapsedTimer timer;
switch (WaitForSingleObjectEx(handle, time, FALSE)) { timer.start();
case WAIT_OBJECT_0: while (timer.elapsed() < time && !d->finished)
ret = true; yieldCurrentThread();
d->handle->join();
break;
case WAIT_FAILED:
qErrnoWarning("QThread::wait: WaitForSingleObjectEx() failed");
break;
case WAIT_ABANDONED:
case WAIT_TIMEOUT:
default:
break;
}
} }
#endif // Q_OS_WINRT #endif // Q_OS_WINRT