Bug 1441498 - Protect mCompositorVsyncDispatcher by lock. r=kats

mCompositorVsyncDispatcher is created and destroyed on main thread. But it is
accessed from Compositor thread or VSyncBridge thread. To avoid race condition
between main thread and Compositor thread/VSyncBridge thread,
mCompositorVsyncDispatcher needs to be protected by lock.
This commit is contained in:
Sotaro Ikeda 2018-03-07 10:53:05 -05:00
parent 21ccca19a4
commit 5e1a7f84b4
2 changed files with 14 additions and 0 deletions

View File

@ -263,6 +263,9 @@ void nsBaseWidget::DestroyCompositor()
// trigger a paint, creating a new compositor, and we don't want to re-use
// the old vsync dispatcher.
if (mCompositorVsyncDispatcher) {
MOZ_ASSERT(mCompositorVsyncDispatcherLock.get());
MutexAutoLock lock(*mCompositorVsyncDispatcherLock.get());
mCompositorVsyncDispatcher->Shutdown();
mCompositorVsyncDispatcher = nullptr;
}
@ -1267,6 +1270,10 @@ void nsBaseWidget::CreateCompositorVsyncDispatcher()
// child process communicate via IPC
// Should be called AFTER gfxPlatform is initialized
if (XRE_IsParentProcess()) {
if (!mCompositorVsyncDispatcherLock) {
mCompositorVsyncDispatcherLock = MakeUnique<Mutex>("mCompositorVsyncDispatcherLock");
}
MutexAutoLock lock(*mCompositorVsyncDispatcherLock.get());
mCompositorVsyncDispatcher = new CompositorVsyncDispatcher();
}
}
@ -1274,6 +1281,9 @@ void nsBaseWidget::CreateCompositorVsyncDispatcher()
already_AddRefed<CompositorVsyncDispatcher>
nsBaseWidget::GetCompositorVsyncDispatcher()
{
MOZ_ASSERT(mCompositorVsyncDispatcherLock.get());
MutexAutoLock lock(*mCompositorVsyncDispatcherLock.get());
RefPtr<CompositorVsyncDispatcher> dispatcher = mCompositorVsyncDispatcher;
return dispatcher.forget();
}

View File

@ -7,6 +7,7 @@
#include "InputData.h"
#include "mozilla/EventForwards.h"
#include "mozilla/Mutex.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WidgetUtils.h"
@ -679,7 +680,10 @@ protected:
RefPtr<LayerManager> mLayerManager;
RefPtr<CompositorSession> mCompositorSession;
RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
RefPtr<IAPZCTreeManager> mAPZC;
RefPtr<GeckoContentController> mRootContentController;
RefPtr<APZEventState> mAPZEventState;