Бранимир Караџић %!s(int64=5) %!d(string=hai) anos
pai
achega
3c49d305e5
Modificáronse 5 ficheiros con 29 adicións e 9 borrados
  1. 1 4
      include/bx/bx.h
  2. 1 1
      include/bx/inline/bx.inl
  3. 18 0
      include/bx/inline/os.inl
  4. 6 0
      include/bx/os.h
  5. 3 4
      src/thread.cpp

+ 1 - 4
include/bx/bx.h

@@ -38,12 +38,9 @@ namespace bx
 	template<class Ty>
 	constexpr bool isTriviallyCopyable();
 
-	///
-	typedef void (*AnyFn)(void);
-
 	///
 	template<typename ProtoT>
-	constexpr ProtoT functionCast(AnyFn _fn);
+	constexpr ProtoT functionCast(void* _fn);
 
 	/// Swap two values.
 	template<typename Ty>

+ 1 - 1
include/bx/inline/bx.inl

@@ -34,7 +34,7 @@ namespace bx
 	}
 
 	template<typename ProtoT>
-	inline constexpr ProtoT functionCast(AnyFn _fn)
+	inline constexpr ProtoT functionCast(void* _fn)
 	{
 		return reinterpret_cast<ProtoT>(_fn);
 	}

+ 18 - 0
include/bx/inline/os.inl

@@ -0,0 +1,18 @@
+/*
+ * Copyright 2010-2020 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#ifndef BX_H_HEADER_GUARD
+#	error "Must be included from bx/os.h!"
+#endif // BX_H_HEADER_GUARD
+
+namespace bx
+{
+	template<typename ProtoT>
+	inline ProtoT dlsym(void* _handle, const StringView& _symbol)
+	{
+		return reinterpret_cast<ProtoT>(dlsym(_handle, _symbol) );
+	}
+
+} // namespace bx

+ 6 - 0
include/bx/os.h

@@ -40,6 +40,10 @@ namespace bx
 	///
 	void* dlsym(void* _handle, const StringView& _symbol);
 
+	///
+	template<typename ProtoT>
+	ProtoT dlsym(void* _handle, const StringView& _symbol);
+
 	///
 	bool getEnv(char* _out, uint32_t* _inOutSize, const StringView& _name);
 
@@ -54,4 +58,6 @@ namespace bx
 
 } // namespace bx
 
+#include "inline/os.inl"
+
 #endif // BX_OS_H_HEADER_GUARD

+ 3 - 4
src/thread.cpp

@@ -280,10 +280,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 = functionCast<SetThreadDescriptionProc>(
-			  dlsym(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription")
-			);
-		if (SetThreadDescription)
+		SetThreadDescriptionProc SetThreadDescription = dlsym<SetThreadDescriptionProc>((void*)GetModuleHandleA("Kernel32.dll"), "SetThreadDescription");
+
+		if (NULL != SetThreadDescription)
 		{
 			uint32_t length = (uint32_t)bx::strLen(_name)+1;
 			uint32_t size = length*sizeof(wchar_t);