Skip to content

Commit

Permalink
Implement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebear94 committed Sep 18, 2024
1 parent d258f9f commit 29a4a01
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/framework/global/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

#include "runtime.h"

#ifdef Q_OS_LINUX
#include "log.h"

#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_MACOS)
#include <pthread.h>
#endif

Expand All @@ -31,14 +33,17 @@ static thread_local std::string s_threadName;
void muse::runtime::setThreadName(const std::string& name)
{
s_threadName = name;
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
// Set thread name through pthreads to aid debuggers that display such names.
// Thread names are limited to 16 bytes on Linux, including the
// terminating null.
DO_ASSERT(name.length() <= 15);
std::string truncated_name = name.length() > 15 ? name.substr(0, 15) : name;
if (pthread_setname_np(pthread_self(), truncated_name.c_str()) > 0) {
qWarning() << Q_FUNC_INFO << "Couldn't set thread name through pthreads";
LOGW() << "Couldn't set thread name through pthreads";
}
#elif defined(Q_OS_MACOS)
pthread_setname_np(name.c_str());
#endif
}

Expand Down

0 comments on commit 29a4a01

Please sign in to comment.