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>
bb10
Leonard Lee 2012-02-03 13:41:47 +01:00 committed by Qt by Nokia
parent 0b9904aab3
commit fb62fdac1c
1 changed files with 18 additions and 0 deletions

View File

@ -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();