diff options
author | Sean Harmer <sean.harmer.qnx@kdab.com> | 2012-04-24 08:29:09 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-30 18:35:42 (GMT) |
commit | aa21fcac3672cc6f0dca064b34bbe02ca4f4def7 (patch) | |
tree | 10572c5494d192e1bc0ee0f6bc05f954af2775d3 | |
parent | e83148a61a6c677b44337f828018a8eb43ea0e74 (diff) | |
download | Qt-aa21fcac3672cc6f0dca064b34bbe02ca4f4def7.zip Qt-aa21fcac3672cc6f0dca064b34bbe02ca4f4def7.tar.gz Qt-aa21fcac3672cc6f0dca064b34bbe02ca4f4def7.tar.bz2 |
Display QThread name for debugging.
Backport of commits:
fb62fdac1cdb4e26388b5bacc7422ec4579b217e
fe7c600fabdfb1b4cbad624ce7cb736e5edce86d
3ef51efbe75bfb9f1dfbe7df073e9eb745a72ad8
47fd7128dba4c38ff1bfcc517fec0f063fb90e4c
Change-Id: Ibcb13ebb2e6cb05ab381328228eca5abdde52ad9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 7cf56b7..fa47d27 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -94,6 +94,10 @@ # endif #endif +#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) +#include <sys/prctl.h> +#endif + #if defined(Q_OS_LINUX) && !defined(SCHED_IDLE) // from linux/sched.h # define SCHED_IDLE 5 @@ -276,6 +280,21 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data) #ifndef QT_NO_THREAD +#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX)) +static void setCurrentThreadName(pthread_t threadId, const char *name) +{ +# if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) + Q_UNUSED(threadId); + prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0); +# elif defined(Q_OS_MAC) + Q_UNUSED(threadId); + pthread_setname_np(name); +# elif defined(Q_OS_QNX) + pthread_setname_np(threadId, name); +# endif +} +#endif + void *QThreadPrivate::start(void *arg) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); @@ -301,6 +320,17 @@ void *QThreadPrivate::start(void *arg) // ### TODO: allow the user to create a custom event dispatcher createEventDispatcher(data); +#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX)) + // sets the name of the current thread. + QString objectName = thr->objectName(); + + if (Q_LIKELY(objectName.isEmpty())) + setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className()); + else + setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit()); + +#endif + emit thr->started(); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_testcancel(); |