Commit 32de9efe by Jamie Madill Committed by Commit Bot

Guard against race in perf warnings.

Expose the "debug" mutex so insertPerfWarning can use it. This was detected using TSAN and MultithreadingTest. Bug: b/168744561 Change-Id: Idde95a7b217f21f007893192a4a1f0a69b4ed3a9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2415184 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent 6939a023
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <mutex>
#include <ostream> #include <ostream>
#include <vector> #include <vector>
...@@ -114,6 +113,12 @@ void InitializeDebugMutexIfNeeded() ...@@ -114,6 +113,12 @@ void InitializeDebugMutexIfNeeded()
} }
} }
std::mutex &GetDebugMutex()
{
ASSERT(g_debugMutex);
return *g_debugMutex;
}
ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr) ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr)
{ {
bool dbgTrace = DebugAnnotationsActive(); bool dbgTrace = DebugAnnotationsActive();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <iomanip> #include <iomanip>
#include <ios> #include <ios>
#include <mutex>
#include <sstream> #include <sstream>
#include <string> #include <string>
...@@ -103,6 +104,8 @@ bool DebugAnnotationsInitialized(); ...@@ -103,6 +104,8 @@ bool DebugAnnotationsInitialized();
void InitializeDebugMutexIfNeeded(); void InitializeDebugMutexIfNeeded();
std::mutex &GetDebugMutex();
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
......
...@@ -340,18 +340,28 @@ size_t Debug::getGroupStackDepth() const ...@@ -340,18 +340,28 @@ size_t Debug::getGroupStackDepth() const
void Debug::insertPerfWarning(GLenum severity, const char *message, uint32_t *repeatCount) const void Debug::insertPerfWarning(GLenum severity, const char *message, uint32_t *repeatCount) const
{ {
bool repeatLast;
{
constexpr uint32_t kMaxRepeat = 4; constexpr uint32_t kMaxRepeat = 4;
std::lock_guard<std::mutex> lock(GetDebugMutex());
if (*repeatCount >= kMaxRepeat) if (*repeatCount >= kMaxRepeat)
{ {
return; return;
} }
++*repeatCount; ++*repeatCount;
repeatLast = (*repeatCount == kMaxRepeat);
}
std::string msg = message; std::string msg = message;
if (*repeatCount == kMaxRepeat) if (repeatLast)
{ {
msg += " (this message will no longer repeat)"; msg += " (this message will no longer repeat)";
} }
// Release the lock before we call insertMessage. It will re-acquire the lock.
insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_PERFORMANCE, 0, severity, std::move(msg), insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_PERFORMANCE, 0, severity, std::move(msg),
gl::LOG_INFO); gl::LOG_INFO);
} }
......
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