diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 3a0bcd40d2..f4e1215747 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -8,7 +8,6 @@ #include "Thread.h" #include "Utilities/JIT.h" #include -#include #include #ifdef _WIN32 @@ -17,6 +16,7 @@ #include #include #else +#define _GNU_SOURCE #ifdef __APPLE__ #define _XOPEN_SOURCE #define __USE_GNU @@ -96,14 +96,6 @@ extern thread_local std::string(*g_tls_log_prefix)(); // Report error and call std::abort(), defined in main.cpp [[noreturn]] void report_fatal_error(std::string_view); -template <> -void fmt_class_string::format(std::string& out, u64 arg) -{ - std::ostringstream ss; - ss << get_object(arg); - out += ss.str(); -} - std::string dump_useful_thread_info() { thread_local volatile bool guard = false; @@ -1644,7 +1636,7 @@ static void append_thread_name(std::string& msg) } else { - fmt::append(msg, "Thread id = %s.\n", std::this_thread::get_id()); + fmt::append(msg, "Thread id = %u.\n", thread_ctrl::get_tid()); } } @@ -3139,6 +3131,8 @@ u64 thread_ctrl::get_tid() { #ifdef _WIN32 return GetCurrentThreadId(); +#elif defined(__linux__) + return syscall(SYS_gettid); #else return reinterpret_cast(pthread_self()); #endif diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index e2ee51176f..b98f9920a0 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -101,7 +101,7 @@ LOG_CHANNEL(q_debug, "QDEBUG"); buf = std::string(_text); // Always print thread id - fmt::append(buf, "\n\nThread id = %s.", std::this_thread::get_id()); + fmt::append(buf, "\n\nThread id = %u.", thread_ctrl::get_tid()); } if (!g_tls_serialize_name.empty()) diff --git a/rpcs3/util/logs.cpp b/rpcs3/util/logs.cpp index b7da7a2398..f9f11bd6f7 100644 --- a/rpcs3/util/logs.cpp +++ b/rpcs3/util/logs.cpp @@ -33,7 +33,7 @@ static std::string default_string() return {}; } - return fmt::format("TID: %s", std::this_thread::get_id()); + return fmt::format("TID: %u", thread_ctrl::get_tid()); } // Thread-specific log prefix provider diff --git a/rpcs3/util/sysinfo.cpp b/rpcs3/util/sysinfo.cpp index 29f62a1525..49ec8e4237 100755 --- a/rpcs3/util/sysinfo.cpp +++ b/rpcs3/util/sysinfo.cpp @@ -652,12 +652,8 @@ u32 utils::get_cpu_model() namespace utils { - extern const u64 main_tid = []() -> u64 + u64 _get_main_tid() { -#ifdef _WIN32 - return GetCurrentThreadId(); -#else - return reinterpret_cast(pthread_self()); -#endif - }(); + return thread_ctrl::get_tid(); + } } diff --git a/rpcs3/util/sysinfo.hpp b/rpcs3/util/sysinfo.hpp index ef14516741..110b8bc4f7 100755 --- a/rpcs3/util/sysinfo.hpp +++ b/rpcs3/util/sysinfo.hpp @@ -66,7 +66,9 @@ namespace utils // A threshold of 0xFFFFFFFF means that the rep movsb is expected to be slow on this platform u32 get_rep_movsb_threshold(); - extern const u64 main_tid; + u64 _get_main_tid(); + + inline const u64 main_tid = _get_main_tid(); #ifdef LLVM_AVAILABLE