Commit 8bea8eec by Yuly Novikov Committed by Commit Bot

Guard ID3DUserDefinedAnnotation access in DebugAnnotator11.

ID3DUserDefinedAnnotation is not thread-safe, like ID3D11DeviceContext, however, it's being accessed from WorkerThread for parallel compilation, thus guard it with mutex lock. Bug: angleproject:3493 Change-Id: Ic7cc7fe03675174e054fe1e11d8d9e05abc716a5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1709726Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
parent f35f1110
...@@ -26,6 +26,7 @@ void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessag ...@@ -26,6 +26,7 @@ void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessag
{ {
std::mbstate_t state = std::mbstate_t(); std::mbstate_t state = std::mbstate_t();
std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state); std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->BeginEvent(mWCharMessage); mUserDefinedAnnotation->BeginEvent(mWCharMessage);
} }
} }
...@@ -35,6 +36,7 @@ void DebugAnnotator11::endEvent(const char *eventName) ...@@ -35,6 +36,7 @@ void DebugAnnotator11::endEvent(const char *eventName)
angle::LoggingAnnotator::endEvent(eventName); angle::LoggingAnnotator::endEvent(eventName);
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->EndEvent(); mUserDefinedAnnotation->EndEvent();
} }
} }
...@@ -46,6 +48,7 @@ void DebugAnnotator11::setMarker(const char *markerName) ...@@ -46,6 +48,7 @@ void DebugAnnotator11::setMarker(const char *markerName)
{ {
std::mbstate_t state = std::mbstate_t(); std::mbstate_t state = std::mbstate_t();
std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state); std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->SetMarker(mWCharMessage); mUserDefinedAnnotation->SetMarker(mWCharMessage);
} }
} }
...@@ -54,6 +57,7 @@ bool DebugAnnotator11::getStatus() ...@@ -54,6 +57,7 @@ bool DebugAnnotator11::getStatus()
{ {
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
std::lock_guard<std::mutex> lock(mAnnotationMutex);
return !!(mUserDefinedAnnotation->GetStatus()); return !!(mUserDefinedAnnotation->GetStatus());
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "libANGLE/LoggingAnnotator.h" #include "libANGLE/LoggingAnnotator.h"
#include <mutex>
namespace rx namespace rx
{ {
...@@ -30,6 +32,7 @@ class DebugAnnotator11 : public angle::LoggingAnnotator ...@@ -30,6 +32,7 @@ class DebugAnnotator11 : public angle::LoggingAnnotator
angle::ComPtr<ID3DUserDefinedAnnotation> mUserDefinedAnnotation; angle::ComPtr<ID3DUserDefinedAnnotation> mUserDefinedAnnotation;
static constexpr size_t kMaxMessageLength = 256; static constexpr size_t kMaxMessageLength = 256;
wchar_t mWCharMessage[kMaxMessageLength]; wchar_t mWCharMessage[kMaxMessageLength];
std::mutex mAnnotationMutex;
}; };
} // namespace rx } // namespace rx
......
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