Switch macOS to use fallback for thread ID

macOS uses a 64-bit thread ID, so rather than truncate this in
GetCurrentThreadId, use pthread_self's result and mix it with the MSBs
of the pointer to reduce the probability of a collision.
This commit is contained in:
Phil Vachon
2025-08-07 10:07:28 -04:00
parent e1db51383b
commit 91f928e018

View File

@@ -29,11 +29,10 @@
#include <winpr/thread.h>
#if defined(__MACOSX__) || defined(__FreeBSD__)
#if defined(__FreeBSD__)
#include <pthread_np.h>
#elif defined(__linux__)
#include <sys/syscall.h>
#endif
#ifndef MIN
@@ -918,14 +917,13 @@ HANDLE _GetCurrentThread(VOID)
DWORD GetCurrentThreadId(VOID)
{
#if defined(__FreeBSD__) || defined(__MACOSX__)
#if defined(__FreeBSD__)
int tid = pthread_getthreadid_np();
return tid;
#elif defined(__linux__)
pid_t tid = syscall(SYS_gettid);
return tid;
#else
#warning Using possibly broken GetCurrentThreadId
pthread_t tid = pthread_self();
/* Since pthread_t can be 64-bits on some systems, take just the */
/* lower 32-bits of it for the thread ID returned by this function. */