Use GlobalLock to protect logging
rtc::CriticalSection has non-trivial destructor and thus
shouldn't be used for variable with static storage duration
Bug: None
Change-Id: I5b9d9036aa90eb0c652f6b17ea1162dea0362640
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156563
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29469}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 0fee5e0..17cf3f5 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -247,6 +247,7 @@
":platform_thread_types",
":stringutils",
":timeutils",
+ "//third_party/abseil-cpp/absl/base:core_headers",
"//third_party/abseil-cpp/absl/meta:type_traits",
"//third_party/abseil-cpp/absl/strings",
]
diff --git a/rtc_base/logging.cc b/rtc_base/logging.cc
index a4aea28..71e0f4f 100644
--- a/rtc_base/logging.cc
+++ b/rtc_base/logging.cc
@@ -35,6 +35,7 @@
#include <cstdarg>
#include <vector>
+#include "absl/base/attributes.h"
#include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
@@ -67,7 +68,7 @@
}
// Global lock for log subsystem, only needed to serialize access to streams_.
-CriticalSection g_log_crit;
+ABSL_CONST_INIT GlobalLock g_log_crit;
} // namespace
// Inefficient default implementation, override is recommended.
@@ -199,7 +200,7 @@
#endif
}
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
for (auto& kv : streams_) {
if (severity_ >= kv.second) {
#if defined(WEBRTC_ANDROID)
@@ -248,7 +249,7 @@
void LogMessage::LogToDebug(LoggingSeverity min_sev) {
g_dbg_sev = min_sev;
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
UpdateMinLogSeverity();
}
@@ -257,7 +258,7 @@
}
int LogMessage::GetLogToStream(LogSink* stream) {
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
LoggingSeverity sev = LS_NONE;
for (auto& kv : streams_) {
if (!stream || stream == kv.first) {
@@ -268,13 +269,13 @@
}
void LogMessage::AddLogToStream(LogSink* stream, LoggingSeverity min_sev) {
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
streams_.push_back(std::make_pair(stream, min_sev));
UpdateMinLogSeverity();
}
void LogMessage::RemoveLogToStream(LogSink* stream) {
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) {
if (stream == it->first) {
streams_.erase(it);
@@ -443,7 +444,7 @@
// TODO(tommi): We're grabbing this lock for every LogMessage instance that
// is going to be logged. This introduces unnecessary synchronization for
// a feature that's mostly used for testing.
- CritScope cs(&g_log_crit);
+ GlobalLockScope cs(&g_log_crit);
if (streams_.size() > 0)
return false;