From 6d034535ae839f858be87bb96f663f08fbbe78f3 Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Wed, 15 Dec 2021 00:38:08 +0100 Subject: [PATCH] rtc_base: define PlatformThread{Id,Ref} on OpenBSD pthread_self(3) returns a phtread_t (aka. pthread *) value. With @ilya-fedin: Redefine thread IDs as `intptr_t` on POSIX platforms unless platform specific functions/types exist so as to avoid the following warning on OpenBSD/amd64 7.0 using clang 11.1.0: ``` platform_thread_types.cc:57:10: error: cast from pointer to smaller type 'rtc::PlatformThreadId' (aka 'int') loses information return reinterpret_cast(pthread_self()); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ``` At least Solaris defines `pid_t` as `long`, i.e. that warning would not occur. OpenBSD defines `pid_t` as `int`. Linux uses its non-portable gettid(3) returing a `pid_t` value, so stick with that. --- src/rtc_base/platform_thread_types.cc | 4 ++++ src/rtc_base/platform_thread_types.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/rtc_base/platform_thread_types.cc b/src/rtc_base/platform_thread_types.cc index 33305d33b..aec96104d 100644 --- a/src/rtc_base/platform_thread_types.cc +++ b/src/rtc_base/platform_thread_types.cc @@ -27,6 +27,8 @@ typedef HRESULT(WINAPI* RTC_SetThreadDescription)(HANDLE hThread, #if defined(WEBRTC_FREEBSD) #include +#elif defined(WEBRTC_OPENBSD) +#include #endif namespace rtc { @@ -115,6 +117,8 @@ void SetCurrentThreadName(const char* name) { prctl(PR_SET_NAME, reinterpret_cast(name)); // NOLINT #elif defined(WEBRTC_FREEBSD) pthread_setname_np(pthread_self(), name); +#elif defined(WEBRTC_OPENBSD) + pthread_set_name_np(pthread_self(), name); #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS) pthread_setname_np(name); #endif diff --git a/src/rtc_base/platform_thread_types.h b/src/rtc_base/platform_thread_types.h index 6b9101eec..60462810e 100644 --- a/src/rtc_base/platform_thread_types.h +++ b/src/rtc_base/platform_thread_types.h @@ -39,7 +39,13 @@ typedef DWORD PlatformThreadRef; typedef zx_handle_t PlatformThreadId; typedef zx_handle_t PlatformThreadRef; #elif defined(WEBRTC_POSIX) +#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS) +typedef mach_port_t PlatformThreadId; +#elif defined(WEBRTC_LINUX) typedef pid_t PlatformThreadId; +#else +typedef intptr_t PlatformThreadId; +#endif typedef pthread_t PlatformThreadRef; #endif