ソースを参照

Added bx::functionCast.

Бранимир Караџић 5 年 前
コミット
18c5b5b6e6
4 ファイル変更17 行追加2 行削除
  1. 1 1
      .appveyor.yml
  2. 7 0
      include/bx/bx.h
  3. 6 0
      include/bx/inline/bx.inl
  4. 3 1
      src/thread.cpp

+ 1 - 1
.appveyor.yml

@@ -6,7 +6,7 @@ os:
 environment:
   matrix:
   - TOOLSET: vs2017
-  - TOOLSET: vs2019
+#  - TOOLSET: vs2019
 
 configuration:
   - Debug

+ 7 - 0
include/bx/bx.h

@@ -38,6 +38,13 @@ namespace bx
 	template<class Ty>
 	constexpr bool isTriviallyCopyable();
 
+	///
+	typedef void (*AnyFn)(void);
+
+	///
+	template<typename ProtoT>
+	constexpr ProtoT functionCast(AnyFn _fn);
+
 	/// Swap two values.
 	template<typename Ty>
 	void swap(Ty& _a, Ty& _b);

+ 6 - 0
include/bx/inline/bx.inl

@@ -33,6 +33,12 @@ namespace bx
 		return __is_trivially_copyable(Ty);
 	}
 
+	template<typename ProtoT>
+	inline constexpr ProtoT functionCast(AnyFn _fn)
+	{
+		return reinterpret_cast<ProtoT>(_fn);
+	}
+
 	template<typename Ty>
 	inline void swap(Ty& _a, Ty& _b)
 	{

+ 3 - 1
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<SetThreadDescriptionProc>(
+			  GetProcAddressA(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription")
+			);
 		if (SetThreadDescription)
 		{
 			uint32_t length = (uint32_t)bx::strLen(_name)+1;