diff options
author | Leonard Lee <leonard.lee@nokia.com> | 2012-02-03 13:41:47 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-10 16:16:00 +0100 |
commit | fb62fdac1cdb4e26388b5bacc7422ec4579b217e (patch) | |
tree | e041e2b809b352c384b1faeab49b166eb475448d | |
parent | 0b9904aab346fc647270ba3fddc8e2b2ef3ed79c (diff) |
Display QThread name for debugging.
Thanks to João's help.
Change-Id: I9ad3035f016945bed9fdf425fc7b7edd5d20822d
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 9ce951cf3b..d458ee9472 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -90,6 +90,10 @@ # endif #endif +#if defined(Q_OS_LINUX) +#include <sys/prctl.h> +#endif + #if defined(Q_OS_LINUX) && !defined(SCHED_IDLE) // from linux/sched.h # define SCHED_IDLE 5 @@ -283,6 +287,20 @@ void *QThreadPrivate::start(void *arg) else createEventDispatcher(data); +#if !defined(QT_NO_DEBUG) && (defined(Q_OS_LINUX) || defined(Q_OS_MAC)) + // sets the name of the current thread. + QByteArray objectName = thr->objectName().toLocal8Bit(); + + if (objectName.isEmpty()) + objectName = thr->metaObject()->className(); + +#if defined(Q_OS_LINUX) + prctl(PR_SET_NAME, (unsigned long)objectName.constData(), 0, 0, 0); +#elif defined(Q_OS_MAC) + pthread_setname_np(objectName.constData()); +#endif +#endif + emit thr->started(); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_testcancel(); |