From 91f928e0184cc50fde85e5b7a3ec9abca7e20772 Mon Sep 17 00:00:00 2001 From: Phil Vachon Date: Thu, 7 Aug 2025 10:07:28 -0400 Subject: [PATCH] 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. --- winpr/libwinpr/thread/thread.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/winpr/libwinpr/thread/thread.c b/winpr/libwinpr/thread/thread.c index d6c546768..e50efec58 100644 --- a/winpr/libwinpr/thread/thread.c +++ b/winpr/libwinpr/thread/thread.c @@ -29,11 +29,10 @@ #include -#if defined(__MACOSX__) || defined(__FreeBSD__) +#if defined(__FreeBSD__) #include #elif defined(__linux__) #include - #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. */