Logging: reduce locking frequency by fixing TODO.

Bug: webrtc:11567
Change-Id: I0cd5062c3a088e3781d009242db32069193fbe82
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176902
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31657}
diff --git a/rtc_base/logging.h b/rtc_base/logging.h
index 0aa1e67..1e5f725 100644
--- a/rtc_base/logging.h
+++ b/rtc_base/logging.h
@@ -46,6 +46,7 @@
 
 #include <errno.h>
 
+#include <atomic>
 #include <sstream>  // no-presubmit-check TODO(webrtc:8982)
 #include <string>
 #include <utility>
@@ -557,6 +558,12 @@
   // The output streams and their associated severities
   static LogSink* streams_;
 
+  // Holds true with high probability if |streams_| is empty, false with high
+  // probability otherwise. Operated on with std::memory_order_relaxed because
+  // it's ok to loose or log some additional statements near the instant streams
+  // are added/removed.
+  static std::atomic<bool> streams_empty_;
+
   // Flags for formatting options
   static bool thread_, timestamp_;