From e7320d22ec04c6d14a38b2bc4172d7c0823f88b5 Mon Sep 17 00:00:00 2001 From: Murray Read Date: Tue, 21 Feb 2012 16:13:10 +0000 Subject: Allowing symbian cleanup code in thread started and finished slots The run() function of QThread was inside a TRAP, but the started() and finished() signals were emitted outside of a TRAP so could not contain Symbian cleanup stack code. This broke compatability with some apps, as the older pthread based implementation had the whole main thread function running inside a TRAP. The started and finished signals are now emitted inside TRAPs, with enhanced leave/exception handling code. Task-number: ou1cimx1#979704 Change-Id: I9b4e50b1085494b5fd5e05efa11739ce19ff26fb Reviewed-by: Shane Kearns --- src/corelib/thread/qthread_symbian.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelib/thread/qthread_symbian.cpp b/src/corelib/thread/qthread_symbian.cpp index fc0e450..fd551ff 100644 --- a/src/corelib/thread/qthread_symbian.cpp +++ b/src/corelib/thread/qthread_symbian.cpp @@ -337,18 +337,26 @@ void *QThreadPrivate::start(void *arg) // ### TODO: allow the user to create a custom event dispatcher createEventDispatcher(data); - emit thr->started(); TRAPD(err, { try { + emit thr->started(); thr->run(); } catch (const std::exception& ex) { qWarning("QThreadPrivate::start: Thread exited on exception %s", ex.what()); + User::Leave(KErrGeneral); // leave to force cleanup stack cleanup } }); if (err) qWarning("QThreadPrivate::start: Thread exited on leave %d", err); - QThreadPrivate::finish(arg); + // finish emits signals which should be wrapped in a trap for Symbian code, but otherwise ignore leaves and exceptions. + TRAP(err, { + try { + QThreadPrivate::finish(arg); + } catch (const std::exception& ex) { + User::Leave(KErrGeneral); // leave to force cleanup stack cleanup + } + }); delete cleanup; -- cgit v0.12