Move log_count_ out of RtcEventLogImpl

The limit on logs is not specific to the implementation of the logs, but is rather shared between all possible logs.
Also, by making it local to the .cc, not a member, we reduce the necessity of making RtcEventLog::Create a friend of the implementation. This necessity is removed completely by a following CL.

BUG=webrtc:8111
NOPRESUBMIT=True

Change-Id: I03044ed55ceeaf0064d5207b7407926571590699
Reviewed-on: https://webrtc-review.googlesource.com/1236
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19870}
diff --git a/logging/rtc_event_log/rtc_event_log.cc b/logging/rtc_event_log/rtc_event_log.cc
index a6b3390..c36afaf 100644
--- a/logging/rtc_event_log/rtc_event_log.cc
+++ b/logging/rtc_event_log/rtc_event_log.cc
@@ -72,6 +72,11 @@
          event_type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT;
 }
 
+// Observe a limit on the number of concurrent logs, so as not to run into
+// OS-imposed limits on open files and/or threads/task-queues.
+// TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
+std::atomic<int> rtc_event_log_count(0);
+
 // TODO(eladalon): This class exists because C++11 doesn't allow transferring a
 // unique_ptr to a lambda (a copy constructor is required). We should get
 // rid of this when we move to C++14.
@@ -157,11 +162,6 @@
   void LogToFile(std::unique_ptr<rtclog::Event> event);
   void StopLogFile(int64_t stop_time);
 
-  // Observe a limit on the number of concurrent logs, so as not to run into
-  // OS-imposed limits on open files and/or threads/task-queues.
-  // TODO(eladalon): Known issue - there's a race over |log_count_|.
-  static std::atomic<int> log_count_;
-
   // Make sure that the event log is "managed" - created/destroyed, as well
   // as started/stopped - from the same thread/task-queue.
   rtc::SequencedTaskChecker owner_sequence_checker_;
@@ -235,8 +235,6 @@
 
 }  // namespace
 
-std::atomic<int> RtcEventLogImpl::log_count_(0);
-
 RtcEventLogImpl::RtcEventLogImpl()
     : file_(FileWrapper::Create()),
       max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()),
@@ -249,7 +247,7 @@
   // If we're logging to the file, this will stop that. Blocking function.
   StopLogging();
 
-  int count = std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1) - 1;
+  int count = std::atomic_fetch_sub(&rtc_event_log_count, 1) - 1;
   RTC_DCHECK_GE(count, 0);
 }
 
@@ -811,13 +809,13 @@
 // RtcEventLog member functions.
 std::unique_ptr<RtcEventLog> RtcEventLog::Create() {
 #ifdef ENABLE_RTC_EVENT_LOG
-  // TODO(eladalon): Known issue - there's a race over |log_count_| here.
+    // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
   constexpr int kMaxLogCount = 5;
-  int count = 1 + std::atomic_fetch_add(&RtcEventLogImpl::log_count_, 1);
+  int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1);
   if (count > kMaxLogCount) {
     LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. "
                     << count - 1 << " logs open already.";
-    std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1);
+    std::atomic_fetch_sub(&rtc_event_log_count, 1);
     return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
   }
   return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl());