Make insertion/retrieval of Debug messages thread-safe

Bug: angleproject:8135
Bug: angleproject:8224
Change-Id: I5ad53b6bb57fe3ee2a261d4e52b7027736fddfd1
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4681843
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
Shahbaz Youssefi
2023-07-13 13:04:37 -04:00
committed by Angle LUCI CQ
parent 435d575c7c
commit 2a52439028
2 changed files with 13 additions and 2 deletions

View File

@@ -199,15 +199,20 @@ void Debug::insertMessage(GLenum source,
return;
}
// TODO(geofflang) Check the synchronous flag and potentially flush messages from another
// thread.
// If isOutputSynchronous(), mMutex does not need to be held, but instead the message should be
// dropped/queued if it doesn't originate from the current context. If !isOutputSynchronous(),
// the callback is expected to be thread-safe per spec, so there is no need for locking.
if (mCallbackFunction != nullptr)
{
// TODO(geofflang) Check the synchronous flag and potentially flush messages from another
// thread.
mCallbackFunction(source, type, id, severity, static_cast<GLsizei>(message.length()),
message.c_str(), mCallbackUserParam);
}
else
{
std::lock_guard<std::mutex> lock(mMutex);
if (mMessages.size() >= mMaxLoggedMessages)
{
// Drop messages over the limit
@@ -234,6 +239,8 @@ size_t Debug::getMessages(GLuint count,
GLsizei *lengths,
GLchar *messageLog)
{
std::lock_guard<std::mutex> lock(mMutex);
size_t messageCount = 0;
size_t messageStringIndex = 0;
while (messageCount <= count && !mMessages.empty())
@@ -290,11 +297,13 @@ size_t Debug::getMessages(GLuint count,
size_t Debug::getNextMessageLength() const
{
std::lock_guard<std::mutex> lock(mMutex);
return mMessages.empty() ? 0 : mMessages.front().message.length() + 1;
}
size_t Debug::getMessageCount() const
{
std::lock_guard<std::mutex> lock(mMutex);
return mMessages.size();
}
@@ -367,6 +376,7 @@ void Debug::insertPerfWarning(GLenum severity, const char *message, uint32_t *re
msg += " (this message will no longer repeat)";
}
// Note: insertMessage will acquire GetDebugMutex(), so it must be released before this call.
insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_PERFORMANCE, 0, severity, std::move(msg),
gl::LOG_INFO, angle::EntryPoint::Invalid);
}

View File

@@ -128,6 +128,7 @@ class Debug : angle::NonCopyable
};
bool mOutputEnabled;
mutable std::mutex mMutex;
GLDEBUGPROCKHR mCallbackFunction;
const void *mCallbackUserParam;
mutable std::deque<Message> mMessages;