Bug 1841030 - cache the thread id in thread-local storage r=profiler-reviewers,canaltinova

Differential Revision: https://phabricator.services.mozilla.com/D205838
This commit is contained in:
Julien Cristau 2024-05-17 14:09:22 +00:00
parent a7cc2c512a
commit 2332065828
2 changed files with 12 additions and 4 deletions

View File

@ -102,8 +102,12 @@ BaseProfilerThreadId profiler_current_thread_id() {
namespace mozilla::baseprofiler {
BaseProfilerThreadId profiler_current_thread_id() {
// glibc doesn't provide a wrapper for gettid() until 2.30
return BaseProfilerThreadId::FromNativeId(syscall(SYS_gettid));
static thread_local pid_t tid;
if (!tid) {
// glibc doesn't provide a wrapper for gettid() until 2.30
tid = static_cast<pid_t>(syscall(SYS_gettid));
}
return BaseProfilerThreadId::FromNativeId(tid);
}
} // namespace mozilla::baseprofiler

View File

@ -67,8 +67,12 @@ ProfilerThreadId profiler_current_thread_id() {
# include <sys/syscall.h>
ProfilerThreadId profiler_current_thread_id() {
// glibc doesn't provide a wrapper for gettid() until 2.30
return ProfilerThreadId::FromNativeId(syscall(SYS_gettid));
static thread_local pid_t tid;
if (!tid) {
// glibc doesn't provide a wrapper for gettid() until 2.30
tid = static_cast<pid_t>(syscall(SYS_gettid));
}
return ProfilerThreadId::FromNativeId(tid);
}
// ------------------------------------------------------- FreeBSD