From 18c5b5b6e648eeae37e249fa5c784f54d14cef81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 2 Sep 2020 20:30:11 -0700 Subject: [PATCH] Added bx::functionCast. --- .appveyor.yml | 2 +- include/bx/bx.h | 7 +++++++ include/bx/inline/bx.inl | 6 ++++++ src/thread.cpp | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 83376c1..b0b1077 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,7 +6,7 @@ os: environment: matrix: - TOOLSET: vs2017 - - TOOLSET: vs2019 +# - TOOLSET: vs2019 configuration: - Debug diff --git a/include/bx/bx.h b/include/bx/bx.h index 9267bbd..a3f592a 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -38,6 +38,13 @@ namespace bx template constexpr bool isTriviallyCopyable(); + /// + typedef void (*AnyFn)(void); + + /// + template + constexpr ProtoT functionCast(AnyFn _fn); + /// Swap two values. template void swap(Ty& _a, Ty& _b); diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index 1cf53a5..152084e 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -33,6 +33,12 @@ namespace bx return __is_trivially_copyable(Ty); } + template + inline constexpr ProtoT functionCast(AnyFn _fn) + { + return reinterpret_cast(_fn); + } + template inline void swap(Ty& _a, Ty& _b) { diff --git a/src/thread.cpp b/src/thread.cpp index 4300517..79a2285 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -279,7 +279,9 @@ namespace bx #elif BX_PLATFORM_WINDOWS // Try to use the new thread naming API from Win10 Creators update onwards if we have it typedef HRESULT (WINAPI *SetThreadDescriptionProc)(HANDLE, PCWSTR); - SetThreadDescriptionProc SetThreadDescription = (SetThreadDescriptionProc)(GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription")); + SetThreadDescriptionProc SetThreadDescription = bx::functionCast( + GetProcAddressA(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription") + ); if (SetThreadDescription) { uint32_t length = (uint32_t)bx::strLen(_name)+1;