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 @@
#include <array>
#include <cstdio>
#include <fstream>
#include <mutex>
#include <ostream>
#include <vector>
......@@ -31,6 +32,8 @@ namespace
DebugAnnotator *g_debugAnnotator = nullptr;
std::mutex *g_debugMutex = nullptr;
constexpr std::array<const char *, LOG_NUM_SEVERITIES> g_logSeverityNames = {
{"EVENT", "WARN", "ERR"}};
......@@ -96,6 +99,14 @@ void UninitializeDebugAnnotations()
g_debugAnnotator = nullptr;
}
void InitializeDebugMutexIfNeeded()
{
if (g_debugMutex == nullptr)
{
g_debugMutex = new std::mutex();
}
}
ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr)
{
bool dbgTrace = DebugAnnotationsActive();
......@@ -140,6 +151,12 @@ LogMessage::LogMessage(const char *function, int line, LogSeverity severity)
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))
{
g_debugAnnotator->logMessage(*this);
......
......@@ -98,6 +98,8 @@ void UninitializeDebugAnnotations();
bool DebugAnnotationsActive();
bool DebugAnnotationsInitialized();
void InitializeDebugMutexIfNeeded();
namespace priv
{
// This class is used to explicitly ignore values in the conditional logging macros. This avoids
......
......@@ -511,6 +511,8 @@ Error Display::initialize()
gl::InitializeDebugAnnotations(&mAnnotator);
gl::InitializeDebugMutexIfNeeded();
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS");
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