From 706028b5684de47addcf580599df5fad1b0cd6a3 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Wed, 16 Sep 2009 13:22:25 +0200 Subject: Fixed the QThread tests for Windows. Backported d04d67e146bce3d407f992c283d7ab3d0c25d428 and 08b54f274d57e4735d0042e295237f176506433d from 4.6. --- tests/auto/qthread/tst_qthread.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp index 34b74d8..587622e 100644 --- a/tests/auto/qthread/tst_qthread.cpp +++ b/tests/auto/qthread/tst_qthread.cpp @@ -629,6 +629,12 @@ void noop(void*) { } typedef HANDLE ThreadHandle; #endif +#ifdef Q_OS_WIN +#define WIN_FIX_STDCALL __stdcall +#else +#define WIN_FIX_STDCALL +#endif + class NativeThreadWrapper { public: @@ -639,7 +645,7 @@ public: void setWaitForStop() { waitForStop = true; } void stop(); - ThreadHandle nativeThread; + ThreadHandle nativeThreadHandle; QThread *qthread; QWaitCondition startCondition; QMutex mutex; @@ -647,7 +653,7 @@ public: QWaitCondition stopCondition; protected: static void *runUnix(void *data); - static void runWin(void *data); + static unsigned WIN_FIX_STDCALL runWin(void *data); FunctionPointer functionPointer; void *data; @@ -658,12 +664,13 @@ void NativeThreadWrapper::start(FunctionPointer functionPointer, void *data) this->functionPointer = functionPointer; this->data = data; #ifdef Q_OS_UNIX - const int state = pthread_create(&nativeThread, 0, NativeThreadWrapper::runUnix, this); + const int state = pthread_create(&nativeThreadHandle, 0, NativeThreadWrapper::runUnix, this); Q_UNUSED(state); #elif defined(Q_OS_WINCE) - nativeThread = CreateThread(NULL, 0 , (LPTHREAD_START_ROUTINE)NativeThreadWrapper::runWin , this, 0, NULL); + nativeThreadHandle = CreateThread(NULL, 0 , (LPTHREAD_START_ROUTINE)NativeThreadWrapper::runWin , this, 0, NULL); #elif defined Q_OS_WIN - nativeThread = (HANDLE)_beginthread(NativeThreadWrapper::runWin, 0, this); + unsigned thrdid = 0; + nativeThreadHandle = (Qt::HANDLE) _beginthreadex(NULL, 0, NativeThreadWrapper::runWin, this, 0, &thrdid); #endif } @@ -677,9 +684,10 @@ void NativeThreadWrapper::startAndWait(FunctionPointer functionPointer, void *da void NativeThreadWrapper::join() { #ifdef Q_OS_UNIX - pthread_join(nativeThread, 0); + pthread_join(nativeThreadHandle, 0); #elif defined Q_OS_WIN - WaitForSingleObject(nativeThread, INFINITE); + WaitForSingleObject(nativeThreadHandle, INFINITE); + CloseHandle(nativeThreadHandle); #endif } @@ -687,7 +695,7 @@ void *NativeThreadWrapper::runUnix(void *that) { NativeThreadWrapper *nativeThreadWrapper = reinterpret_cast(that); - // Adoppt thread, create QThread object. + // Adopt thread, create QThread object. nativeThreadWrapper->qthread = QThread::currentThread(); // Release main thread. @@ -709,9 +717,10 @@ void *NativeThreadWrapper::runUnix(void *that) return 0; } -void NativeThreadWrapper::runWin(void *data) +unsigned WIN_FIX_STDCALL NativeThreadWrapper::runWin(void *data) { runUnix(data); + return 0; } void NativeThreadWrapper::stop() -- cgit v0.12