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 <mbonadei@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24660}
This commit is contained in:
parent
57606328f6
commit
6c092d2993
@ -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",
|
||||
|
||||
@ -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<void* volatile*>(&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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user