Bug 1515689 - Fix initialization/destruction race in UiCompositorControllerParent r=botond
authorJames Willcox <snorp@snorp.net>
Thu, 17 Jan 2019 19:37:32 +0000
changeset 511560 06c3ceef79456689c1b53d4bd07f75cfb71be142
parent 511559 b0377ec57ddd05e44c8336609f794986c719ab50
child 511561 255d5e9dc5ca7e1bbd00852c0c7fc24836f1f757
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1515689
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515689 - Fix initialization/destruction race in UiCompositorControllerParent r=botond It looks like we can do initialization and destruction from the UI thread before the bits that run on the Compositor thread have run. Avoid this by synchronously waiting on the Compositor. Differential Revision: https://phabricator.services.mozilla.com/D16596
gfx/layers/ipc/UiCompositorControllerParent.cpp
--- a/gfx/layers/ipc/UiCompositorControllerParent.cpp
+++ b/gfx/layers/ipc/UiCompositorControllerParent.cpp
@@ -12,16 +12,17 @@
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/Move.h"
 #include "mozilla/Unused.h"
 
 #include "FrameMetrics.h"
+#include "SynchronousTask.h"
 
 namespace mozilla {
 namespace layers {
 
 typedef CompositorBridgeParent::LayerTreeState LayerTreeState;
 
 /* static */ RefPtr<UiCompositorControllerParent>
 UiCompositorControllerParent::GetFromRootLayerTreeId(
@@ -272,19 +273,26 @@ UiCompositorControllerParent::UiComposit
 UiCompositorControllerParent::~UiCompositorControllerParent() {
   MOZ_COUNT_DTOR(UiCompositorControllerParent);
 }
 
 void UiCompositorControllerParent::InitializeForSameProcess() {
   // This function is called by UiCompositorControllerChild in the main thread.
   // So dispatch to the compositor thread to Initialize.
   if (!CompositorThreadHolder::IsInCompositorThread()) {
-    CompositorThreadHolder::Loop()->PostTask(NewRunnableMethod(
-        "layers::UiCompositorControllerParent::InitializeForSameProcess", this,
-        &UiCompositorControllerParent::InitializeForSameProcess));
+    SynchronousTask task(
+        "UiCompositorControllerParent::InitializeForSameProcess");
+
+    CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction(
+        "UiCompositorControllerParent::InitializeForSameProcess", [&]() {
+          AutoCompleteTask complete(&task);
+          InitializeForSameProcess();
+        }));
+
+    task.Wait();
     return;
   }
 
   Initialize();
 }
 
 void UiCompositorControllerParent::InitializeForOutOfProcess() {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());