Skip to content

Commit

Permalink
rtc_base: define PlatformThread{Id,Ref} on OpenBSD
Browse files Browse the repository at this point in the history
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<PlatformThreadId>(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.
  • Loading branch information
klemensn authored and john-preston committed Feb 25, 2022
1 parent adad2cf commit 6d03453
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rtc_base/platform_thread_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef HRESULT(WINAPI* RTC_SetThreadDescription)(HANDLE hThread,

#if defined(WEBRTC_FREEBSD)
#include <pthread_np.h>
#elif defined(WEBRTC_OPENBSD)
#include <pthread_np.h>
#endif

namespace rtc {
Expand Down Expand Up @@ -115,6 +117,8 @@ void SetCurrentThreadName(const char* name) {
prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(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
Expand Down
6 changes: 6 additions & 0 deletions src/rtc_base/platform_thread_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6d03453

Please sign in to comment.