forked from mirrors/gecko-dev
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:
parent
a7cc2c512a
commit
2332065828
2 changed files with 12 additions and 4 deletions
|
|
@ -102,8 +102,12 @@ BaseProfilerThreadId profiler_current_thread_id() {
|
||||||
namespace mozilla::baseprofiler {
|
namespace mozilla::baseprofiler {
|
||||||
|
|
||||||
BaseProfilerThreadId profiler_current_thread_id() {
|
BaseProfilerThreadId profiler_current_thread_id() {
|
||||||
// glibc doesn't provide a wrapper for gettid() until 2.30
|
static thread_local pid_t tid;
|
||||||
return BaseProfilerThreadId::FromNativeId(syscall(SYS_gettid));
|
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
|
} // namespace mozilla::baseprofiler
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,12 @@ ProfilerThreadId profiler_current_thread_id() {
|
||||||
# include <sys/syscall.h>
|
# include <sys/syscall.h>
|
||||||
|
|
||||||
ProfilerThreadId profiler_current_thread_id() {
|
ProfilerThreadId profiler_current_thread_id() {
|
||||||
// glibc doesn't provide a wrapper for gettid() until 2.30
|
static thread_local pid_t tid;
|
||||||
return ProfilerThreadId::FromNativeId(syscall(SYS_gettid));
|
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
|
// ------------------------------------------------------- FreeBSD
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue