From d9edc6896615c5ab9908be56865e526407a80902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 15:45:51 +0200 Subject: [PATCH] Remove unnecessary use of thread local storage --- CMakeLists.txt | 3 ++- Common/Common.vcxproj | 3 ++- Common/Common.vcxproj.filters | 3 ++- Common/CommonFuncs.h | 8 -------- Common/{Misc.cpp => SysError.cpp} | 27 +++++++++++-------------- Common/SysError.h | 10 +++++++++ Core/MIPS/ARM64/Arm64CompALU.cpp | 3 ++- UWP/CommonUWP/CommonUWP.vcxproj | 3 ++- UWP/CommonUWP/CommonUWP.vcxproj.filters | 3 ++- android/jni/Android.mk | 2 +- libretro/Makefile.common | 2 +- 11 files changed, 36 insertions(+), 31 deletions(-) rename Common/{Misc.cpp => SysError.cpp} (82%) create mode 100644 Common/SysError.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 960d4b3a2d..01467f9b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,11 +475,12 @@ add_library(Common STATIC Common/MemArena.h Common/MemoryUtil.cpp Common/MemoryUtil.h - Common/Misc.cpp Common/OSVersion.cpp Common/OSVersion.h Common/StringUtils.cpp Common/StringUtils.h + Common/SysError.h + Common/SysError.cpp Common/ThreadPools.cpp Common/ThreadPools.h Common/ThreadSafeList.h diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 7be07259f0..7d48de5757 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -415,6 +415,7 @@ + @@ -501,7 +502,7 @@ - + Create diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 2e61356786..981ac5d5a3 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -96,6 +96,7 @@ + @@ -105,7 +106,6 @@ - @@ -164,6 +164,7 @@ + diff --git a/Common/CommonFuncs.h b/Common/CommonFuncs.h index 4e5adc8beb..72cf14356f 100644 --- a/Common/CommonFuncs.h +++ b/Common/CommonFuncs.h @@ -78,11 +78,3 @@ inline u64 __rotr64(u64 x, unsigned int shift){ #endif #define Crash() {__debugbreak();} #endif // WIN32 ndef - -// Generic function to get last error message. -// Call directly after the command or use the error num. -// This function might change the error code. -// Defined in Misc.cpp. -const char *GetLastErrorMsg(); -const char *GetStringErrorMsg(int errCode); - diff --git a/Common/Misc.cpp b/Common/SysError.cpp similarity index 82% rename from Common/Misc.cpp rename to Common/SysError.cpp index a13924b1bf..c3f900ed67 100644 --- a/Common/Misc.cpp +++ b/Common/SysError.cpp @@ -15,14 +15,11 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ +#include +#include + #include "util/text/utf8.h" -#include "Common.h" - -#include - -#if defined(__APPLE__) -#define __thread -#endif +#include "SysError.h" #ifdef _WIN32 #include "CommonWindows.h" @@ -31,8 +28,7 @@ // Generic function to get last error message. // Call directly after the command or use the error num. // This function might change the error code. -const char *GetLastErrorMsg() -{ +std::string GetLastErrorMsg() { #ifdef _WIN32 return GetStringErrorMsg(GetLastError()); #else @@ -40,25 +36,26 @@ const char *GetLastErrorMsg() #endif } -const char *GetStringErrorMsg(int errCode) { +std::string GetStringErrorMsg(int errCode) { static const size_t buff_size = 1023; + #ifdef _WIN32 - static thread_local wchar_t err_strw[buff_size] = {}; + wchar_t err_strw[buff_size] = {}; FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_strw, buff_size, NULL); - static thread_local char err_str[buff_size] = {}; + char err_str[buff_size] = {}; snprintf(err_str, buff_size, "%s", ConvertWStringToUTF8(err_strw).c_str()); + return std::string(err_str); #else - static thread_local char err_str[buff_size] = {}; + char err_str[buff_size] = {}; // Thread safe (XSI-compliant) if (strerror_r(errCode, err_str, buff_size) == 0) { return "Unknown error"; } -#endif - return err_str; +#endif } diff --git a/Common/SysError.h b/Common/SysError.h new file mode 100644 index 0000000000..b425b34fdc --- /dev/null +++ b/Common/SysError.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +// Generic function to get last error message. +// Call directly after the command or use the error num. +// This function might change the error code. +// Defined in Misc.cpp. +std::string GetLastErrorMsg(); +std::string GetStringErrorMsg(int errCode); diff --git a/Core/MIPS/ARM64/Arm64CompALU.cpp b/Core/MIPS/ARM64/Arm64CompALU.cpp index f97ba0dee7..df195209f6 100644 --- a/Core/MIPS/ARM64/Arm64CompALU.cpp +++ b/Core/MIPS/ARM64/Arm64CompALU.cpp @@ -20,11 +20,12 @@ #include +#include "Common/ByteSwap.h" +#include "Common/CPUDetect.h" #include "Core/MIPS/MIPS.h" #include "Core/MIPS/MIPSCodeUtils.h" #include "Core/MIPS/ARM64/Arm64Jit.h" #include "Core/MIPS/ARM64/Arm64RegCache.h" -#include "Common/CPUDetect.h" using namespace MIPSAnalyst; diff --git a/UWP/CommonUWP/CommonUWP.vcxproj b/UWP/CommonUWP/CommonUWP.vcxproj index 1424c98b62..7cc5e4fe86 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj +++ b/UWP/CommonUWP/CommonUWP.vcxproj @@ -420,6 +420,7 @@ + @@ -455,7 +456,7 @@ - + diff --git a/UWP/CommonUWP/CommonUWP.vcxproj.filters b/UWP/CommonUWP/CommonUWP.vcxproj.filters index 62ed966957..ece02a7b10 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj.filters +++ b/UWP/CommonUWP/CommonUWP.vcxproj.filters @@ -28,7 +28,7 @@ - + @@ -89,6 +89,7 @@ + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 3060d22e87..71b73e9c60 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -221,10 +221,10 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Common/MemoryUtil.cpp \ $(SRC)/Common/FileUtil.cpp \ $(SRC)/Common/StringUtils.cpp \ + $(SRC)/Common/SysError.cpp \ $(SRC)/Common/ThreadPools.cpp \ $(SRC)/Common/Timer.cpp \ $(SRC)/Common/TimeUtil.cpp \ - $(SRC)/Common/Misc.cpp \ $(SRC)/GPU/Math3D.cpp \ $(SRC)/GPU/GPU.cpp \ $(SRC)/GPU/GPUCommon.cpp \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 1d61dd6fcd..ef385e1e5a 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -153,7 +153,7 @@ SOURCES_CXX += \ $(COMMONDIR)/LogManager.cpp \ $(COMMONDIR)/OSVersion.cpp \ $(COMMONDIR)/MemoryUtil.cpp \ - $(COMMONDIR)/Misc.cpp \ + $(COMMONDIR)/SysError.cpp \ $(COMMONDIR)/StringUtils.cpp \ $(COMMONDIR)/Timer.cpp \ $(COMMONDIR)/TimeUtil.cpp \