Fix native thread handle usage on win32

This commit is contained in:
sfan5 2024-01-02 17:50:44 +01:00
parent 8674dc831d
commit 7c7ae79f9f

@ -59,6 +59,8 @@ DEALINGS IN THE SOFTWARE.
#include <mach/thread_act.h> #include <mach/thread_act.h>
#endif #endif
// See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method
#define win32_native_handle() ((HANDLE) getThreadHandle())
Thread::Thread(const std::string &name) : Thread::Thread(const std::string &name) :
m_name(name), m_name(name),
@ -81,9 +83,8 @@ Thread::~Thread()
m_running = false; m_running = false;
#if defined(_WIN32) #if defined(_WIN32)
// See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method TerminateThread(win32_native_handle(), 0);
TerminateThread((HANDLE) m_thread_obj->native_handle(), 0); CloseHandle(win32_native_handle());
CloseHandle((HANDLE) m_thread_obj->native_handle());
#else #else
// We need to pthread_kill instead on Android since NDKv5's pthread // We need to pthread_kill instead on Android since NDKv5's pthread
// implementation is incomplete. // implementation is incomplete.
@ -261,13 +262,9 @@ bool Thread::bindToProcessor(unsigned int proc_number)
return false; return false;
#elif _MSC_VER #elif defined(_WIN32)
return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number); return SetThreadAffinityMask(win32_native_handle(), 1 << proc_number);
#elif __MINGW32__
return SetThreadAffinityMask(pthread_gethandle(getThreadHandle()), 1 << proc_number);
#elif __FreeBSD_version >= 702106 || defined(__linux__) || defined(__DragonFly__) #elif __FreeBSD_version >= 702106 || defined(__linux__) || defined(__DragonFly__)
@ -320,13 +317,9 @@ bool Thread::bindToProcessor(unsigned int proc_number)
bool Thread::setPriority(int prio) bool Thread::setPriority(int prio)
{ {
#ifdef _MSC_VER #ifdef _WIN32
return SetThreadPriority(getThreadHandle(), prio); return SetThreadPriority(win32_native_handle(), prio);
#elif __MINGW32__
return SetThreadPriority(pthread_gethandle(getThreadHandle()), prio);
#else #else