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:
Gerald Squelart 2021-08-11 03:27:52 +00:00
parent 032f23b189
commit 056d185383
5 changed files with 7 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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