Commit 3848ed7f by Michael Brase Committed by Copybara-Service

Add GetTID() implementation for Fuchsia

The GetTID() now uses the value of the current thread handle from
zx_thread_self() on Fuchsia for the thread ID. This is better than the default
implementation which uses pthread_self(), since that results in a 64-bit
pointer being truncated into the 32-bit pid_t type.

PiperOrigin-RevId: 660270084
Change-Id: I7c8b4a26cca775be62eb6f6926cb734cbb893585
parent bd0c9c58
......@@ -46,6 +46,10 @@
#include <rtems.h>
#endif
#if defined(__Fuchsia__)
#include <zircon/process.h>
#endif
#include <string.h>
#include <cassert>
......@@ -461,6 +465,16 @@ pid_t GetTID() {
return reinterpret_cast<pid_t>(thread);
}
#elif defined(__Fuchsia__)
pid_t GetTID() {
// Use our thread handle as the TID, which should be unique within this
// process (but may not be globally unique). The handle value was chosen over
// a kernel object ID (KOID) because zx_handle_t (32-bits) can be cast to a
// pid_t type without loss of precision, but a zx_koid_t (64-bits) cannot.
return static_cast<pid_t>(zx_thread_self());
}
#else
// Fallback implementation of `GetTID` using `pthread_self`.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment