Simplify how we set thread name for UNIX threads
Passing on the thread ID is confusing, as it's not really what the function does. The QNX code path can resolve the thread ID by itself. Change-Id: I5f0d54621058576cdcf3707d36a11762fe2383c8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
74045f8b9a
commit
b1fe198d87
@ -311,16 +311,14 @@ 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)
|
||||
static void setCurrentThreadName(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);
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
@ -361,14 +359,13 @@ void *QThreadPrivate::start(void *arg)
|
||||
|
||||
#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
|
||||
{
|
||||
// sets the name of the current thread.
|
||||
QString objectName = thr->objectName();
|
||||
|
||||
pthread_t thread_id = from_HANDLE<pthread_t>(data->threadId.load());
|
||||
if (Q_LIKELY(objectName.isEmpty()))
|
||||
setCurrentThreadName(thread_id, thr->metaObject()->className());
|
||||
// Sets the name of the current thread. We can only do this
|
||||
// when the thread is starting, as we don't have a cross
|
||||
// platform way of setting the name of an arbitrary thread.
|
||||
if (Q_LIKELY(thr->objectName().isEmpty()))
|
||||
setCurrentThreadName(thr->metaObject()->className());
|
||||
else
|
||||
setCurrentThreadName(thread_id, objectName.toLocal8Bit());
|
||||
setCurrentThreadName(thr->objectName().toLocal8Bit());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user