Revert of Improving the fake clock and using it to fix a flaky STUN timeout test. (patchset #10 id:180001 of https://codereview.webrtc.org/2024813004/ )

Reason for revert:
There seems to be a TSan warning that wasn't caught by the trybot: https://build.chromium.org/p/client.webrtc/builders/Linux%20Tsan%20v2/builds/6732/steps/peerconnection_unittests/logs/stdio

Apparently a thread is still alive even after destroying WebRTCSession. Need to think of a way to fix this, without adding a critical section around g_clock (since that would hurt performance).

Original issue's description:
> Improving the fake clock and using it to fix a flaky STUN timeout test.
>
> When the fake clock's time is advanced, it now ensures all pending
> queued messages have been dispatched. This allows us to write a
> "SIMULATED_WAIT" macro that ticks the simulated clock by milliseconds up
> until the target time.
>
> Useful in this case, where we know the STUN timeout should take a total
> of 9500ms, but it would be overly complex to write test code that waits
> for each individual timeout, ensures a STUN packet has been
> retransmited, etc.
>
> (The test described above *should* be written, but it belongs in
> p2ptransportchannel_unittest.cc, not webrtcsession_unittest.cc).
>
> Committed: https://crrev.com/ffbe0e17e2c9b7fe101023acf40574dc0c95631a
> Cr-Commit-Position: refs/heads/master@{#13043}

TBR=pthatcher@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review-Url: https://codereview.webrtc.org/2038213002
Cr-Commit-Position: refs/heads/master@{#13045}
diff --git a/webrtc/base/messagequeue.cc b/webrtc/base/messagequeue.cc
index 4c2331b..da50e23 100644
--- a/webrtc/base/messagequeue.cc
+++ b/webrtc/base/messagequeue.cc
@@ -9,14 +9,17 @@
  */
 #include <algorithm>
 
-#include "webrtc/base/atomicops.h"
 #include "webrtc/base/checks.h"
 #include "webrtc/base/common.h"
 #include "webrtc/base/logging.h"
 #include "webrtc/base/messagequeue.h"
-#include "webrtc/base/thread.h"
 #include "webrtc/base/trace_event.h"
 
+namespace {
+
+enum { MSG_WAKE_MESSAGE_QUEUE = 1 };
+}
+
 namespace rtc {
 
 const int kMaxMsgLatency = 150;  // 150 ms
@@ -38,7 +41,8 @@
   return instance_ != NULL;
 }
 
-MessageQueueManager::MessageQueueManager() {}
+MessageQueueManager::MessageQueueManager() {
+}
 
 MessageQueueManager::~MessageQueueManager() {
 }
@@ -104,36 +108,26 @@
     (*iter)->Clear(handler);
 }
 
-void MessageQueueManager::ProcessAllMessageQueues() {
+void MessageQueueManager::WakeAllMessageQueues() {
   if (!instance_) {
     return;
   }
-  return Instance()->ProcessAllMessageQueuesInternal();
+  return Instance()->WakeAllMessageQueuesInternal();
 }
 
-void MessageQueueManager::ProcessAllMessageQueuesInternal() {
+void MessageQueueManager::WakeAllMessageQueuesInternal() {
 #if CS_DEBUG_CHECKS  // CurrentThreadIsOwner returns true by default.
   ASSERT(!crit_.CurrentThreadIsOwner());  // See note above.
 #endif
-  // Post a delayed message at the current time and wait for it to be dispatched
-  // on all queues, which will ensure that all messages that came before it were
-  // also dispatched.
-  volatile int queues_not_done;
-  auto functor = [&queues_not_done] { AtomicOps::Decrement(&queues_not_done); };
-  FunctorMessageHandler<void, decltype(functor)> handler(functor);
-  {
-    CritScope cs(&crit_);
-    queues_not_done = static_cast<int>(message_queues_.size());
-    for (MessageQueue* queue : message_queues_) {
-      queue->PostDelayed(0, &handler);
-    }
+  CritScope cs(&crit_);
+  for (MessageQueue* queue : message_queues_) {
+    // Posting an arbitrary message will force the message queue to wake up.
+    queue->Post(this, MSG_WAKE_MESSAGE_QUEUE);
   }
-  // Note: One of the message queues may have been on this thread, which is why
-  // we can't synchronously wait for queues_not_done to go to 0; we need to
-  // process messages as well.
-  while (AtomicOps::AcquireLoad(&queues_not_done) > 0) {
-    rtc::Thread::Current()->ProcessMessages(0);
-  }
+}
+
+void MessageQueueManager::OnMessage(Message* pmsg) {
+  RTC_DCHECK(pmsg->message_id == MSG_WAKE_MESSAGE_QUEUE);
 }
 
 //------------------------------------------------------------------