mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1721569 - Use std::this_thread::get_id() on other platforms - r=florian
Now `profiler_current_thread_id()` is available on all platforms, at all tier levels. Differential Revision: https://phabricator.services.mozilla.com/D121053
This commit is contained in:
parent
032f23b189
commit
056d185383
@ -114,7 +114,7 @@ BaseProfilerThreadId profiler_current_thread_id() {
|
|||||||
namespace mozilla::baseprofiler {
|
namespace mozilla::baseprofiler {
|
||||||
|
|
||||||
BaseProfilerThreadId profiler_current_thread_id() {
|
BaseProfilerThreadId profiler_current_thread_id() {
|
||||||
return BaseProfilerThreadId{};
|
return BaseProfilerThreadId::FromNativeId(std::this_thread::get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mozilla::baseprofiler
|
} // namespace mozilla::baseprofiler
|
||||||
|
@ -61,8 +61,10 @@ using ThreadIdType = long;
|
|||||||
// ------------------------------------------------------- Others
|
// ------------------------------------------------------- Others
|
||||||
# else
|
# else
|
||||||
|
|
||||||
|
# include <thread>
|
||||||
|
|
||||||
namespace mozilla::baseprofiler::detail {
|
namespace mozilla::baseprofiler::detail {
|
||||||
using ThreadIdType = int;
|
using ThreadIdType = std::thread::id;
|
||||||
} // namespace mozilla::baseprofiler::detail
|
} // namespace mozilla::baseprofiler::detail
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
@ -187,8 +187,6 @@ void TestProfilerUtils() {
|
|||||||
static_assert(std::is_same_v<
|
static_assert(std::is_same_v<
|
||||||
decltype(mozilla::baseprofiler::profiler_current_thread_id()),
|
decltype(mozilla::baseprofiler::profiler_current_thread_id()),
|
||||||
BaseProfilerThreadId>);
|
BaseProfilerThreadId>);
|
||||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(__ANDROID__) || \
|
|
||||||
defined(ANDROID) || defined(XP_LINUX) || defined(XP_FREEBSD)
|
|
||||||
BaseProfilerThreadId mainTestThreadId =
|
BaseProfilerThreadId mainTestThreadId =
|
||||||
mozilla::baseprofiler::profiler_current_thread_id();
|
mozilla::baseprofiler::profiler_current_thread_id();
|
||||||
MOZ_RELEASE_ASSERT(mainTestThreadId.IsSpecified());
|
MOZ_RELEASE_ASSERT(mainTestThreadId.IsSpecified());
|
||||||
@ -209,14 +207,6 @@ void TestProfilerUtils() {
|
|||||||
MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_is_main_thread());
|
MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_is_main_thread());
|
||||||
});
|
});
|
||||||
testThread.join();
|
testThread.join();
|
||||||
#else
|
|
||||||
// Yet-unsupported platforms.
|
|
||||||
MOZ_RELEASE_ASSERT(
|
|
||||||
!mozilla::baseprofiler::profiler_current_thread_id().IsSpecified());
|
|
||||||
MOZ_RELEASE_ASSERT(
|
|
||||||
!mozilla::baseprofiler::profiler_main_thread_id().IsSpecified());
|
|
||||||
MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_is_main_thread());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No conversions between processes and threads.
|
// No conversions between processes and threads.
|
||||||
|
@ -87,7 +87,9 @@ ProfilerThreadId profiler_current_thread_id() {
|
|||||||
// ------------------------------------------------------- Others
|
// ------------------------------------------------------- Others
|
||||||
# else
|
# else
|
||||||
|
|
||||||
ProfilerThreadId profiler_current_thread_id() { return ProfilerThreadId{}; }
|
ProfilerThreadId profiler_current_thread_id() {
|
||||||
|
return ProfilerThreadId::FromNativeId(std::this_thread::get_id());
|
||||||
|
}
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
#endif // End of non-XP_WIN.
|
#endif // End of non-XP_WIN.
|
||||||
|
@ -72,8 +72,6 @@ TEST(GeckoProfiler, ProfilerUtils)
|
|||||||
EXPECT_EQ(profiler_current_thread_id(),
|
EXPECT_EQ(profiler_current_thread_id(),
|
||||||
baseprofiler::profiler_current_thread_id());
|
baseprofiler::profiler_current_thread_id());
|
||||||
|
|
||||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(__ANDROID__) || \
|
|
||||||
defined(ANDROID) || defined(XP_LINUX) || defined(XP_FREEBSD)
|
|
||||||
ProfilerThreadId mainTestThreadId = profiler_current_thread_id();
|
ProfilerThreadId mainTestThreadId = profiler_current_thread_id();
|
||||||
EXPECT_TRUE(mainTestThreadId.IsSpecified());
|
EXPECT_TRUE(mainTestThreadId.IsSpecified());
|
||||||
|
|
||||||
@ -98,16 +96,6 @@ TEST(GeckoProfiler, ProfilerUtils)
|
|||||||
EXPECT_FALSE(baseprofiler::profiler_is_main_thread());
|
EXPECT_FALSE(baseprofiler::profiler_is_main_thread());
|
||||||
});
|
});
|
||||||
testThread.join();
|
testThread.join();
|
||||||
#else
|
|
||||||
// Yet-unsupported platforms.
|
|
||||||
EXPECT_FALSE(profiler_current_thread_id().IsSpecified());
|
|
||||||
EXPECT_FALSE(profiler_main_thread_id().IsSpecified());
|
|
||||||
EXPECT_FALSE(profiler_is_main_thread());
|
|
||||||
|
|
||||||
EXPECT_FALSE(baseprofiler::profiler_current_thread_id().IsSpecified());
|
|
||||||
EXPECT_FALSE(baseprofiler::profiler_main_thread_id().IsSpecified());
|
|
||||||
EXPECT_FALSE(baseprofiler::profiler_is_main_thread());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_GECKO_PROFILER
|
#ifdef MOZ_GECKO_PROFILER
|
||||||
|
Loading…
Reference in New Issue
Block a user