Commit 23ed69cb by jchen10 Committed by Commit Bot

Make WARN() and ERR() thread safe

This adds a global mutex lock to protect logging messages from worker threads. BUG=922936 Change-Id: I42e2a7b560da6f6a8b120b74252adce115ccda20 Reviewed-on: https://chromium-review.googlesource.com/c/1429479 Commit-Queue: Jie A Chen <jie.a.chen@intel.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9429f216
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <array> #include <array>
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <mutex>
#include <ostream> #include <ostream>
#include <vector> #include <vector>
...@@ -31,6 +32,8 @@ namespace ...@@ -31,6 +32,8 @@ namespace
DebugAnnotator *g_debugAnnotator = nullptr; DebugAnnotator *g_debugAnnotator = nullptr;
std::mutex *g_debugMutex = nullptr;
constexpr std::array<const char *, LOG_NUM_SEVERITIES> g_logSeverityNames = { constexpr std::array<const char *, LOG_NUM_SEVERITIES> g_logSeverityNames = {
{"EVENT", "WARN", "ERR"}}; {"EVENT", "WARN", "ERR"}};
...@@ -96,6 +99,14 @@ void UninitializeDebugAnnotations() ...@@ -96,6 +99,14 @@ void UninitializeDebugAnnotations()
g_debugAnnotator = nullptr; g_debugAnnotator = nullptr;
} }
void InitializeDebugMutexIfNeeded()
{
if (g_debugMutex == nullptr)
{
g_debugMutex = new std::mutex();
}
}
ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr) ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr)
{ {
bool dbgTrace = DebugAnnotationsActive(); bool dbgTrace = DebugAnnotationsActive();
...@@ -140,6 +151,12 @@ LogMessage::LogMessage(const char *function, int line, LogSeverity severity) ...@@ -140,6 +151,12 @@ LogMessage::LogMessage(const char *function, int line, LogSeverity severity)
LogMessage::~LogMessage() LogMessage::~LogMessage()
{ {
std::unique_lock<std::mutex> lock;
if (g_debugMutex != nullptr)
{
lock = std::unique_lock<std::mutex>(*g_debugMutex);
}
if (DebugAnnotationsInitialized() && (mSeverity == LOG_ERR || mSeverity == LOG_WARN)) if (DebugAnnotationsInitialized() && (mSeverity == LOG_ERR || mSeverity == LOG_WARN))
{ {
g_debugAnnotator->logMessage(*this); g_debugAnnotator->logMessage(*this);
......
...@@ -98,6 +98,8 @@ void UninitializeDebugAnnotations(); ...@@ -98,6 +98,8 @@ void UninitializeDebugAnnotations();
bool DebugAnnotationsActive(); bool DebugAnnotationsActive();
bool DebugAnnotationsInitialized(); bool DebugAnnotationsInitialized();
void InitializeDebugMutexIfNeeded();
namespace priv namespace priv
{ {
// This class is used to explicitly ignore values in the conditional logging macros. This avoids // This class is used to explicitly ignore values in the conditional logging macros. This avoids
......
...@@ -511,6 +511,8 @@ Error Display::initialize() ...@@ -511,6 +511,8 @@ Error Display::initialize()
gl::InitializeDebugAnnotations(&mAnnotator); gl::InitializeDebugAnnotations(&mAnnotator);
gl::InitializeDebugMutexIfNeeded();
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS"); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS");
TRACE_EVENT0("gpu.angle", "egl::Display::initialize"); TRACE_EVENT0("gpu.angle", "egl::Display::initialize");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment