From d409621f2880b3b6c2b7197b97837bfe87a93cb6 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Thu, 24 Nov 2022 09:01:35 +0100 Subject: [PATCH] Fix SetCurrentThreadName() for Fuchsia. CL suggested by lingxueluo@. Bug: b/236891952 Change-Id: I960d5b016186e9784e0af5e86608891a06e78b7e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/284920 Reviewed-by: Tomas Gunnarsson Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#38723} --- rtc_base/BUILD.gn | 5 ++++- rtc_base/platform_thread_types.cc | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index c5b9024cc1..fa60656541 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -314,7 +314,10 @@ rtc_library("platform_thread_types") { "platform_thread_types.cc", "platform_thread_types.h", ] - deps = [ ":macromagic" ] + deps = [ + ":checks", + ":macromagic", + ] } rtc_source_set("refcount") { diff --git a/rtc_base/platform_thread_types.cc b/rtc_base/platform_thread_types.cc index b0243b41dc..d64ea689bb 100644 --- a/rtc_base/platform_thread_types.cc +++ b/rtc_base/platform_thread_types.cc @@ -25,6 +25,13 @@ typedef HRESULT(WINAPI* RTC_SetThreadDescription)(HANDLE hThread, PCWSTR lpThreadDescription); #endif +#if defined(WEBRTC_FUCHSIA) +#include +#include + +#include "rtc_base/checks.h" +#endif + namespace rtc { PlatformThreadId CurrentThreadId() { @@ -109,6 +116,10 @@ void SetCurrentThreadName(const char* name) { prctl(PR_SET_NAME, reinterpret_cast(name)); // NOLINT #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS) pthread_setname_np(name); +#elif defined(WEBRTC_FUCHSIA) + zx_status_t status = zx_object_set_property(zx_thread_self(), ZX_PROP_NAME, + name, strlen(name)); + RTC_DCHECK_EQ(status, ZX_OK); #endif }