Skip to content

Commit

Permalink
Added bx::functionCast.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Sep 3, 2020
1 parent 306bf14 commit 18c5b5b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Expand Up @@ -6,7 +6,7 @@ os:
environment:
matrix:
- TOOLSET: vs2017
- TOOLSET: vs2019
# - TOOLSET: vs2019

configuration:
- Debug
Expand Down
7 changes: 7 additions & 0 deletions include/bx/bx.h
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions include/bx/inline/bx.inl
Expand Up @@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/thread.cpp
Expand Up @@ -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")

This comment has been minimized.

Copy link
@cloudwu

cloudwu Sep 3, 2020

Contributor

This is no GetProcAddressA , I think it should be GetProcAddress

https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress

);
if (SetThreadDescription)
{
uint32_t length = (uint32_t)bx::strLen(_name)+1;
Expand Down

0 comments on commit 18c5b5b

Please sign in to comment.