Commit 4043b9d1 by Jamie Madill Committed by Commit Bot

Guard against data race with MemoryProgramCache.

Uses the display global mutex. Caught with angle_end2end_tests MultithreadingTest and TSAN. Bug: b/168744561 Change-Id: I5a60346cb5f95ff506dc166604eeae501863a774 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2415182Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 5f8af83f
...@@ -8475,6 +8475,11 @@ void Context::onGPUSwitch() ...@@ -8475,6 +8475,11 @@ void Context::onGPUSwitch()
initRendererString(); initRendererString();
} }
std::mutex &Context::getProgramCacheMutex() const
{
return mDisplay->getProgramCacheMutex();
}
// ErrorSet implementation. // ErrorSet implementation.
ErrorSet::ErrorSet(Context *context) : mContext(context) {} ErrorSet::ErrorSet(Context *context) : mContext(context) {}
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#ifndef LIBANGLE_CONTEXT_H_ #ifndef LIBANGLE_CONTEXT_H_
#define LIBANGLE_CONTEXT_H_ #define LIBANGLE_CONTEXT_H_
#include <mutex>
#include <set> #include <set>
#include <string> #include <string>
...@@ -506,6 +507,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl ...@@ -506,6 +507,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
angle::Result prepareForDispatch(); angle::Result prepareForDispatch();
MemoryProgramCache *getMemoryProgramCache() const { return mMemoryProgramCache; } MemoryProgramCache *getMemoryProgramCache() const { return mMemoryProgramCache; }
std::mutex &getProgramCacheMutex() const;
bool hasBeenCurrent() const { return mHasBeenCurrent; } bool hasBeenCurrent() const { return mHasBeenCurrent; }
egl::Display *getDisplay() const { return mDisplay; } egl::Display *getDisplay() const { return mDisplay; }
......
...@@ -256,6 +256,7 @@ class Display final : public LabeledObject, ...@@ -256,6 +256,7 @@ class Display final : public LabeledObject,
egl::Error handleGPUSwitch(); egl::Error handleGPUSwitch();
std::mutex &getDisplayGlobalMutex() { return mDisplayGlobalMutex; } std::mutex &getDisplayGlobalMutex() { return mDisplayGlobalMutex; }
std::mutex &getProgramCacheMutex() { return mProgramCacheMutex; }
private: private:
Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice); Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
...@@ -327,6 +328,7 @@ class Display final : public LabeledObject, ...@@ -327,6 +328,7 @@ class Display final : public LabeledObject,
std::vector<angle::ScratchBuffer> mZeroFilledBuffers; std::vector<angle::ScratchBuffer> mZeroFilledBuffers;
std::mutex mDisplayGlobalMutex; std::mutex mDisplayGlobalMutex;
std::mutex mProgramCacheMutex;
}; };
} // namespace egl } // namespace egl
......
...@@ -1437,6 +1437,7 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1437,6 +1437,7 @@ angle::Result Program::linkImpl(const Context *context)
// TODO: http://anglebug.com/4530: Enable program caching for separable programs // TODO: http://anglebug.com/4530: Enable program caching for separable programs
if (cache && !isSeparable()) if (cache && !isSeparable())
{ {
std::lock_guard<std::mutex> cacheLock(context->getProgramCacheMutex());
angle::Result cacheResult = cache->getProgram(context, this, &programHash); angle::Result cacheResult = cache->getProgram(context, this, &programHash);
ANGLE_TRY(cacheResult); ANGLE_TRY(cacheResult);
...@@ -1658,6 +1659,7 @@ void Program::resolveLinkImpl(const Context *context) ...@@ -1658,6 +1659,7 @@ void Program::resolveLinkImpl(const Context *context)
postResolveLink(context); postResolveLink(context);
// Save to the program cache. // Save to the program cache.
std::lock_guard<std::mutex> cacheLock(context->getProgramCacheMutex());
MemoryProgramCache *cache = context->getMemoryProgramCache(); MemoryProgramCache *cache = context->getMemoryProgramCache();
// TODO: http://anglebug.com/4530: Enable program caching for separable programs // TODO: http://anglebug.com/4530: Enable program caching for separable programs
if (cache && !isSeparable() && if (cache && !isSeparable() &&
......
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