diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/assert.h | 7 | ||||
| -rw-r--r-- | src/common/param_package.h | 2 | ||||
| -rw-r--r-- | src/common/thread.cpp | 12 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/common/assert.h b/src/common/assert.h index 5b67c5c52..06d7b5612 100644 --- a/src/common/assert.h +++ b/src/common/assert.h | |||
| @@ -17,11 +17,12 @@ | |||
| 17 | // enough for our purposes. | 17 | // enough for our purposes. |
| 18 | template <typename Fn> | 18 | template <typename Fn> |
| 19 | #if defined(_MSC_VER) | 19 | #if defined(_MSC_VER) |
| 20 | __declspec(noinline, noreturn) | 20 | [[msvc::noinline, noreturn]] |
| 21 | #elif defined(__GNUC__) | 21 | #elif defined(__GNUC__) |
| 22 | __attribute__((noinline, noreturn, cold)) | 22 | [[gnu::cold, gnu::noinline, noreturn]] |
| 23 | #endif | 23 | #endif |
| 24 | static void assert_noinline_call(const Fn& fn) { | 24 | static void |
| 25 | assert_noinline_call(const Fn& fn) { | ||
| 25 | fn(); | 26 | fn(); |
| 26 | Crash(); | 27 | Crash(); |
| 27 | exit(1); // Keeps GCC's mouth shut about this actually returning | 28 | exit(1); // Keeps GCC's mouth shut about this actually returning |
diff --git a/src/common/param_package.h b/src/common/param_package.h index c8a70bfa9..c13e45479 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h | |||
| @@ -19,7 +19,7 @@ public: | |||
| 19 | explicit ParamPackage(const std::string& serialized); | 19 | explicit ParamPackage(const std::string& serialized); |
| 20 | ParamPackage(std::initializer_list<DataType::value_type> list); | 20 | ParamPackage(std::initializer_list<DataType::value_type> list); |
| 21 | ParamPackage(const ParamPackage& other) = default; | 21 | ParamPackage(const ParamPackage& other) = default; |
| 22 | ParamPackage(ParamPackage&& other) = default; | 22 | ParamPackage(ParamPackage&& other) noexcept = default; |
| 23 | 23 | ||
| 24 | ParamPackage& operator=(const ParamPackage& other) = default; | 24 | ParamPackage& operator=(const ParamPackage& other) = default; |
| 25 | ParamPackage& operator=(ParamPackage&& other) = default; | 25 | ParamPackage& operator=(ParamPackage&& other) = default; |
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_funcs.h" | ||
| 6 | #include "common/logging/log.h" | ||
| 5 | #include "common/thread.h" | 7 | #include "common/thread.h" |
| 6 | #ifdef __APPLE__ | 8 | #ifdef __APPLE__ |
| 7 | #include <mach/mach.h> | 9 | #include <mach/mach.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include <unistd.h> | 21 | #include <unistd.h> |
| 20 | #endif | 22 | #endif |
| 21 | 23 | ||
| 24 | #include <string> | ||
| 25 | |||
| 22 | #ifdef __FreeBSD__ | 26 | #ifdef __FreeBSD__ |
| 23 | #define cpu_set_t cpuset_t | 27 | #define cpu_set_t cpuset_t |
| 24 | #endif | 28 | #endif |
| @@ -110,6 +114,14 @@ void SetCurrentThreadName(const char* name) { | |||
| 110 | pthread_set_name_np(pthread_self(), name); | 114 | pthread_set_name_np(pthread_self(), name); |
| 111 | #elif defined(__NetBSD__) | 115 | #elif defined(__NetBSD__) |
| 112 | pthread_setname_np(pthread_self(), "%s", (void*)name); | 116 | pthread_setname_np(pthread_self(), "%s", (void*)name); |
| 117 | #elif defined(__linux__) | ||
| 118 | // Linux limits thread names to 15 characters and will outright reject any | ||
| 119 | // attempt to set a longer name with ERANGE. | ||
| 120 | std::string truncated(name, std::min(strlen(name), static_cast<size_t>(15))); | ||
| 121 | if (int e = pthread_setname_np(pthread_self(), truncated.c_str())) { | ||
| 122 | errno = e; | ||
| 123 | LOG_ERROR(Common, "Failed to set thread name to '{}': {}", truncated, GetLastErrorMsg()); | ||
| 124 | } | ||
| 113 | #else | 125 | #else |
| 114 | pthread_setname_np(pthread_self(), name); | 126 | pthread_setname_np(pthread_self(), name); |
| 115 | #endif | 127 | #endif |