diff options
author | Murray Read <ext-murray.2.read@nokia.com> | 2012-03-26 13:02:10 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-27 16:14:09 (GMT) |
commit | f33ad9d6548d4544ad2ea6229b47093efa9ea0ef (patch) | |
tree | 9d03f380f112f3364a6273225d24204844051dce /src | |
parent | dc13840ca95d453be239d2f4e10ef9f2edaf6c3a (diff) | |
download | Qt-f33ad9d6548d4544ad2ea6229b47093efa9ea0ef.zip Qt-f33ad9d6548d4544ad2ea6229b47093efa9ea0ef.tar.gz Qt-f33ad9d6548d4544ad2ea6229b47093efa9ea0ef.tar.bz2 |
Give QThread threads better names on Symbian
QThread sets the name of a Symbian thread that it creates. This name
can appear in a number of debugging scenarios, and it can give useful
information. However the existing name set by QThread has not been
informative.
This change improves the amount of information in the thread name.
Threads are now named as:
<object name>_<class name>_v=<class vptr>_<random>
The class name and vptr can be used to identify the QThread subclass
type. In the case of a QThread subclass that generates a .moc file,
the class name will be the true class name. However for other cases,
eg where QThread is used directly, or is subclassed without a QOBJECT
declaration, the name may simply be "QThread", and the vptr field
might then be more informative.
This change also allows the use of RTTI to get the true class name,
through a rebuild of Qt, defining the macro name
QT_USE_RTTI_IN_THREAD_CLASSNAME. This is not enabled by default, as
there may be Symbian cases where RTTI does not work.
Task-number: QTBUG-24950
Change-Id: Ifae9c6cb64638e95a01d34e421aa36f6fd0e7444
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Reviewed-by: Gareth Stockwell <ext-gareth.stockwell@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/thread/qthread_symbian.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/corelib/thread/qthread_symbian.cpp b/src/corelib/thread/qthread_symbian.cpp index fd551ff..0cddb68 100644 --- a/src/corelib/thread/qthread_symbian.cpp +++ b/src/corelib/thread/qthread_symbian.cpp @@ -53,6 +53,11 @@ #include <hal_data.h> #include <e32math.h> +// This can be manually enabled if debugging thread problems +#ifdef QT_USE_RTTI_IN_THREAD_CLASSNAME +#include <typeinfo> +#endif + // You only find these enumerations on Symbian^3 onwards, so we need to provide our own // to remain compatible with older releases. They won't be called by pre-Sym^3 SDKs. @@ -520,17 +525,23 @@ void QThread::start(Priority priority) d->stackSize = 0x14000; // Maximum stack size on Symbian. int code = KErrAlreadyExists; - QString objName = objectName(); - TPtrC objNamePtr(qt_QString2TPtrC(objName)); + QString className(QLatin1String(metaObject()->className())); +#ifdef QT_USE_RTTI_IN_THREAD_CLASSNAME + // use RTTI, if enabled, to get a more accurate className. This must be manually enabled. + const char* rttiName = typeid(*this).name(); + if (rttiName) + className = QLatin1String(rttiName); +#endif + QString threadNameBase = QString(QLatin1String("%1_%2_v=0x%3_")).arg(objectName()).arg(className).arg(*(uint*)this,8,16,QLatin1Char('0')); + TPtrC threadNameBasePtr(qt_QString2TPtrC(threadNameBase)); TName name; - objNamePtr.Set(objNamePtr.Left(qMin(objNamePtr.Length(), name.MaxLength() - 16))); + threadNameBasePtr.Set(threadNameBasePtr.Left(qMin(threadNameBasePtr.Length(), name.MaxLength() - 8))); const int MaxRetries = 10; for (int i=0; i<MaxRetries && code == KErrAlreadyExists; i++) { - // generate a thread name using a similar method to libpthread in Symbian + // generate a thread name with a random component to avoid and resolve name collisions // a named thread can be opened from another process name.Zero(); - name.Append(objNamePtr); - name.AppendNumFixedWidth(int(this), EHex, 8); + name.Append(threadNameBasePtr); name.AppendNumFixedWidth(Math::Random(), EHex, 8); code = d->data->symbian_thread_handle.Create(name, (TThreadFunction) QThreadPrivate::start, d->stackSize, NULL, this); } |