From 1a0fd473bcea62d1e471bb49ca06d931d0deb616 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Mon, 4 May 2009 14:43:52 +0300 Subject: Fix for thread termination in Symbian OS. Since Open C does not support all pthread funtions, thread termination in Symbian OS is implemented differently. Before this fix, QThread::Terminate just terminated the native thread. Because QThreadPrivate::finish was not called, the 'running', 'finished' etc flags were not set and thread termination related signals were not correctly emitted. In UNIX finish is called by pthread_cancel since thread cancelation points are set. In Symbian OS we need to call it manually since pthread_cancel is not supported. It was necessary to add a new parameter to QThreadPrivate::finish, which tells whether the native thread handle can be closed or not. This was required since 'symbian_thread_handle.Terminate' will not succeed if thread handle is closed. On the other hand we cannot first terminate the thread and then call QThreadPrivate::finish. Autotest: qthread and qprocess passes in HW (5800) and Emulator Review By: miikka.heikkinen@digia.com --- src/corelib/thread/qthread_p.h | 2 +- src/corelib/thread/qthread_unix.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index f07fad8..0bf773c 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -182,7 +182,7 @@ public: static void *start(void *arg); #if defined(Q_OS_SYMBIAN) - static void finish(void *arg, bool lockAnyway=true); + static void finish(void *arg, bool lockAnyway=true, bool closeNativeHandle=true); #else static void finish(void *); #endif diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index aad55bc..567c936 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -226,7 +226,7 @@ void *QThreadPrivate::start(void *arg) } #ifdef Q_OS_SYMBIAN -void QThreadPrivate::finish(void *arg, bool lockAnyway) +void QThreadPrivate::finish(void *arg, bool lockAnyway, bool closeNativeHandle) #else void QThreadPrivate::finish(void *arg) #endif @@ -258,7 +258,8 @@ void QThreadPrivate::finish(void *arg) d->thread_id = 0; #ifdef Q_OS_SYMBIAN - d->data->symbian_thread_handle.Close(); + if (closeNativeHandle) + d->data->symbian_thread_handle.Close(); #endif d->thread_done.wakeAll(); #ifdef Q_OS_SYMBIAN @@ -530,10 +531,11 @@ void QThread::terminate() d->terminatePending = true; return; } - - d->data->symbian_thread_handle.Terminate(KErrNone); - + d->terminated = true; + QThreadPrivate::finish(this, false, false); + d->data->symbian_thread_handle.Terminate(KErrNone); + d->data->symbian_thread_handle.Close(); #endif -- cgit v0.12