summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTrond Kjernaasen <trond@trolltech.com>2009-09-16 11:22:25 (GMT)
committerTrond Kjernaasen <trond@trolltech.com>2009-09-16 11:22:25 (GMT)
commit706028b5684de47addcf580599df5fad1b0cd6a3 (patch)
treea53cbb4b6011d0045e8603a075385f93775d497e /tests
parentd851010a10c9a75fd8fb165bc239d5d3b805c0b8 (diff)
downloadQt-706028b5684de47addcf580599df5fad1b0cd6a3.zip
Qt-706028b5684de47addcf580599df5fad1b0cd6a3.tar.gz
Qt-706028b5684de47addcf580599df5fad1b0cd6a3.tar.bz2
Fixed the QThread tests for Windows.
Backported d04d67e146bce3d407f992c283d7ab3d0c25d428 and 08b54f274d57e4735d0042e295237f176506433d from 4.6.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qthread/tst_qthread.cpp27
1 files 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<NativeThreadWrapper*>(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()