mirror of
https://github.com/godotengine/godot-angle-static.git
synced 2026-01-03 14:09:33 +03:00
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:
committed by
Angle LUCI CQ
parent
435d575c7c
commit
2a52439028
@@ -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);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ class Debug : angle::NonCopyable
|
||||
};
|
||||
|
||||
bool mOutputEnabled;
|
||||
mutable std::mutex mMutex;
|
||||
GLDEBUGPROCKHR mCallbackFunction;
|
||||
const void *mCallbackUserParam;
|
||||
mutable std::deque<Message> mMessages;
|
||||
|
||||
Reference in New Issue
Block a user