summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-08-31 21:31:48 +0200
committerGitHub <noreply@github.com>2020-08-31 21:31:48 +0200
commitb5ed2d408c45720d88d47fd6fe79d7858edd4523 (patch)
treed68f7d4d4994c2e51a04ae3a9390b6ef3dcb5c78 /src/common
parentMerge pull request #4614 from ReinUsesLisp/fix-extended-state-again (diff)
parentFix thread naming on Linux, which limits names to 15 bytes. (diff)
downloadyuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar.gz
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar.bz2
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar.lz
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar.xz
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.tar.zst
yuzu-b5ed2d408c45720d88d47fd6fe79d7858edd4523.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/thread.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index 8e5935e6a..d2c1ac60d 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.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