Delete use of RWLockWrapper from SimulatedClock

Instead, use lock-less reads and increments of current time,
with relaxed memory order.

Bug: webrtc:12102
Change-Id: I0e804d97d7adb5d3d115544487573ea03d132590
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191225
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32543}
diff --git a/system_wrappers/source/clock.cc b/system_wrappers/source/clock.cc
index e0f4b40..0ae624d 100644
--- a/system_wrappers/source/clock.cc
+++ b/system_wrappers/source/clock.cc
@@ -26,7 +26,6 @@
 #endif  // defined(WEBRTC_POSIX)
 
 #include "rtc_base/synchronization/mutex.h"
-#include "rtc_base/synchronization/rw_lock_wrapper.h"
 #include "rtc_base/time_utils.h"
 
 namespace webrtc {
@@ -239,16 +238,15 @@
 }
 
 SimulatedClock::SimulatedClock(int64_t initial_time_us)
-    : SimulatedClock(Timestamp::Micros(initial_time_us)) {}
+    : time_us_(initial_time_us) {}
 
 SimulatedClock::SimulatedClock(Timestamp initial_time)
-    : time_(initial_time), lock_(RWLockWrapper::CreateRWLock()) {}
+    : SimulatedClock(initial_time.us()) {}
 
 SimulatedClock::~SimulatedClock() {}
 
 Timestamp SimulatedClock::CurrentTime() {
-  ReadLockScoped synchronize(*lock_);
-  return time_;
+  return Timestamp::Micros(time_us_.load(std::memory_order_relaxed));
 }
 
 NtpTime SimulatedClock::CurrentNtpTime() {
@@ -271,9 +269,13 @@
   AdvanceTime(TimeDelta::Micros(microseconds));
 }
 
+// TODO(bugs.webrtc.org(12102): It's desirable to let a single thread own
+// advancement of the clock. We could then replace this read-modify-write
+// operation with just a thread checker. But currently, that breaks a couple of
+// tests, in particular, RepeatingTaskTest.ClockIntegration and
+// CallStatsTest.LastProcessedRtt.
 void SimulatedClock::AdvanceTime(TimeDelta delta) {
-  WriteLockScoped synchronize(*lock_);
-  time_ += delta;
+  time_us_.fetch_add(delta.us(), std::memory_order_relaxed);
 }
 
 }  // namespace webrtc