From 6c092d29930d25bbba7a6968022ebbccb1389e84 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 10 Sep 2018 13:27:11 +0200 Subject: [PATCH] Refactor initialization of GetRealTimeClock singleton. This CL also fixes no_exit_time_destructors in system_wrappers. Bug: webrtc:9693 Change-Id: Ieba752f50949f862244a8348ffc1bed3c2f0150f Reviewed-on: https://webrtc-review.googlesource.com/99081 Commit-Queue: Mirko Bonadei Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#24660} --- system_wrappers/BUILD.gn | 1 - system_wrappers/source/clock.cc | 29 ++++++----------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index ad917451ad..a926147bba 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -14,7 +14,6 @@ import("../webrtc.gni") rtc_static_library("system_wrappers") { visibility = [ "*" ] - configs += [ "..:no_exit_time_destructors" ] sources = [ "include/clock.h", "include/cpu_info.h", diff --git a/system_wrappers/source/clock.cc b/system_wrappers/source/clock.cc index c9940fbe99..35ab5f0878 100644 --- a/system_wrappers/source/clock.cc +++ b/system_wrappers/source/clock.cc @@ -200,32 +200,15 @@ class UnixRealTimeClock : public RealTimeClock { }; #endif // defined(WEBRTC_POSIX) -#if defined(WEBRTC_WIN) -static WindowsRealTimeClock* volatile g_shared_clock = nullptr; -#endif // defined(WEBRTC_WIN) - Clock* Clock::GetRealTimeClock() { #if defined(WEBRTC_WIN) - // This read relies on volatile read being atomic-load-acquire. This is - // true in MSVC since at least 2005: - // "A read of a volatile object (volatile read) has Acquire semantics" - if (g_shared_clock != nullptr) - return g_shared_clock; - WindowsRealTimeClock* clock = new WindowsRealTimeClock; - if (InterlockedCompareExchangePointer( - reinterpret_cast(&g_shared_clock), clock, nullptr) != - nullptr) { - // g_shared_clock was assigned while we constructed/tried to assign our - // instance, delete our instance and use the existing one. - delete clock; - } - return g_shared_clock; + static Clock* const clock = new WindowsRealTimeClock(); #elif defined(WEBRTC_POSIX) - static UnixRealTimeClock clock; - return &clock; -#else // defined(WEBRTC_POSIX) - return nullptr; -#endif // !defined(WEBRTC_WIN) || defined(WEBRTC_POSIX) + static Clock* const clock = new UnixRealTimeClock(); +#else + static Clock* const clock = nullptr; +#endif + return clock; } SimulatedClock::SimulatedClock(int64_t initial_time_us)