Skip to content

Commit

Permalink
Support thread naming on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Valakor committed Jan 8, 2024
1 parent 5502716 commit 90c8e2e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/Remotery.c
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,14 @@ static void rmtGetThreadName(rmtThreadId thread_id, rmtThreadHandle thread_handl
len = strnlen_s(out_thread_name, thread_name_size);
itoahex_s(out_thread_name + len, thread_name_size - len, thread_id);

#elif defined(RMT_PLATFORM_MACOS)

int ret = pthread_getname_np(pthread_self(), out_thread_name, thread_name_size);
if (ret != 0 || out_thread_name[0] == '\0')
{
rmtGetThreadNameFallback(out_thread_name, thread_name_size);
}

#elif defined(RMT_PLATFORM_LINUX) && RMT_USE_POSIX_THREADNAMES && !defined(__FreeBSD__) && !defined(__OpenBSD__)

prctl(PR_GET_NAME, out_thread_name, 0, 0, 0);
Expand Down Expand Up @@ -7374,6 +7382,8 @@ static void SetDebuggerThreadName(const char* name)
{
}
#endif
#elif defined(RMT_PLATFORM_MACOS)
pthread_setname_np(name);
#else
RMT_UNREFERENCED_PARAMETER(name);
#endif
Expand Down Expand Up @@ -7413,7 +7423,7 @@ RMT_API void _rmt_SetCurrentThreadName(rmtPStr thread_name)
SetDebuggerThreadName(thread_name);

// Send the thread name for lookup
#ifdef RMT_PLATFORM_WINDOWS
#if defined(RMT_PLATFORM_WINDOWS) || defined(RMT_PLATFORM_MACOS)
name_length = strnlen_s(thread_profiler->threadName, 64);
QueueAddToStringTable(g_Remotery->mq_to_rmt_thread, thread_profiler->threadNameHash, thread_name, name_length, NULL);
#endif
Expand Down

0 comments on commit 90c8e2e

Please sign in to comment.