Browse Source
Merge pull request #4461 from comex/thread-names
Fix thread naming on Linux, which limits names to 15 bytes.
pull/15/merge
LC
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
13 additions and
1 deletions
-
src/common/thread.cpp
-
src/core/cpu_manager.cpp
|
|
|
@ -2,6 +2,8 @@ |
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/thread.h"
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <mach/mach.h>
|
|
|
|
@ -19,6 +21,8 @@ |
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#define cpu_set_t cpuset_t
|
|
|
|
#endif
|
|
|
|
@ -110,6 +114,14 @@ void SetCurrentThreadName(const char* name) { |
|
|
|
pthread_set_name_np(pthread_self(), name); |
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
pthread_setname_np(pthread_self(), "%s", (void*)name); |
|
|
|
#elif defined(__linux__)
|
|
|
|
// Linux limits thread names to 15 characters and will outright reject any
|
|
|
|
// attempt to set a longer name with ERANGE.
|
|
|
|
std::string truncated(name, std::min(strlen(name), static_cast<size_t>(15))); |
|
|
|
if (int e = pthread_setname_np(pthread_self(), truncated.c_str())) { |
|
|
|
errno = e; |
|
|
|
LOG_ERROR(Common, "Failed to set thread name to '{}': {}", truncated, GetLastErrorMsg()); |
|
|
|
} |
|
|
|
#else
|
|
|
|
pthread_setname_np(pthread_self(), name); |
|
|
|
#endif
|
|
|
|
|
|
|
|
@ -328,7 +328,7 @@ void CpuManager::RunThread(std::size_t core) { |
|
|
|
system.RegisterCoreThread(core); |
|
|
|
std::string name; |
|
|
|
if (is_multicore) { |
|
|
|
name = "yuzu:CoreCPUThread_" + std::to_string(core); |
|
|
|
name = "yuzu:CPUCore_" + std::to_string(core); |
|
|
|
} else { |
|
|
|
name = "yuzu:CPUThread"; |
|
|
|
} |
|
|
|
|