[BlackBerry] fix confusing destruction sequence in LayerCompositingThread
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Mar 2012 20:06:14 +0000 (20:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Mar 2012 20:06:14 +0000 (20:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81706

Patch by Joe Mason <jmason@rim.com> on 2012-03-27
Reviewed by Rob Buis.

LayerCompositingThread has a destructor that does a synchronous
dispatch to the compositing thread and then does the actual cleanup
from a helper function. This is confusing.It should be the
opposite: the helper function dispatches to the compositing thread,
which calls delete.

No new tests since the existing animation tests will exercise this
code.

* platform/graphics/blackberry/LayerCompositingThread.cpp:
(WebCore::LayerCompositingThread::destroyOnCompositingThread):
(WebCore):
(WebCore::LayerCompositingThread::~LayerCompositingThread):
* platform/graphics/blackberry/LayerCompositingThread.h:
(LayerCompositingThread):
(WTF):
(WTF::::deref):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@112304 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp
Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h

index 6177432c8e5cff5ee2a3f3b2296596a5c7fd555f..5cc35238aace772408b4d8f7cc2b75811edc871c 100644 (file)
@@ -1,3 +1,28 @@
+2012-03-27  Joe Mason  <jmason@rim.com>
+
+        [BlackBerry] fix confusing destruction sequence in LayerCompositingThread
+        https://bugs.webkit.org/show_bug.cgi?id=81706
+
+        Reviewed by Rob Buis.
+
+        LayerCompositingThread has a destructor that does a synchronous
+        dispatch to the compositing thread and then does the actual cleanup
+        from a helper function. This is confusing.It should be the
+        opposite: the helper function dispatches to the compositing thread,
+        which calls delete.
+
+        No new tests since the existing animation tests will exercise this
+        code.
+
+        * platform/graphics/blackberry/LayerCompositingThread.cpp:
+        (WebCore::LayerCompositingThread::destroyOnCompositingThread):
+        (WebCore):
+        (WebCore::LayerCompositingThread::~LayerCompositingThread):
+        * platform/graphics/blackberry/LayerCompositingThread.h:
+        (LayerCompositingThread):
+        (WTF):
+        (WTF::::deref):
+
 2012-03-27  Alexey Proskuryakov  <ap@apple.com>
 
         [Mac] Stop using NSMapTable in FormDataStreamMac.mm
index 89a9cf7716a4c40f90c17b9cfd38b9814e3bc629..a41497dfe5de123ace0f02e838423919929f0b6d 100644 (file)
@@ -71,14 +71,6 @@ LayerCompositingThread::LayerCompositingThread(LayerType type, PassRefPtr<LayerT
 {
 }
 
-LayerCompositingThread::~LayerCompositingThread()
-{
-    // Unfortunately, ThreadSafeShared<T> is hardwired to call T::~T().
-    // To switch threads in case the last reference is released on the
-    // WebKit thread, we send a sync message to the compositing thread.
-    destroyOnCompositingThread();
-}
-
 void LayerCompositingThread::destroyOnCompositingThread()
 {
     if (!isCompositingThread()) {
@@ -88,6 +80,13 @@ void LayerCompositingThread::destroyOnCompositingThread()
         return;
     }
 
+    delete this;
+}
+
+LayerCompositingThread::~LayerCompositingThread()
+{
+    ASSERT(isCompositingThread());
+
     m_tiler->layerCompositingThreadDestroyed();
 
     ASSERT(!superlayer());
index e1de74e8f1f0c95fa556e515cafc2dea500b68dc..4d9c291318f16be3cd273c4d7643c20e96029aa6 100644 (file)
@@ -53,7 +53,6 @@ class Buffer;
 
 namespace WebCore {
 
-class DestroyOnCompositingThread;
 class LayerRenderer;
 
 class LayerCompositingThread : public ThreadSafeRefCounted<LayerCompositingThread>, public LayerData, public BlackBerry::Platform::GuardedPointerBase {
@@ -145,7 +144,7 @@ public:
 private:
     LayerCompositingThread(LayerType, PassRefPtr<LayerTiler>);
 
-    friend class DestroyOnCompositingThread;
+    friend class WTF::ThreadSafeRefCounted<WebCore::LayerCompositingThread>;
     void destroyOnCompositingThread();
 
     void updateTileContents(const IntRect& tile);
@@ -188,8 +187,25 @@ private:
     RefPtr<LayerTiler> m_tiler;
 };
 
+} // namespace WebCore
+
+namespace WTF {
+
+// LayerCompositingThread objects must be destroyed on the compositing thread.
+// But it's possible for the last reference to be held by the WebKit thread.
+// So we create a custom specialization of ThreadSafeRefCounted which calls a
+// function that ensures the destructor is called on the correct thread, rather
+// than calling delete directly.
+template<>
+inline void ThreadSafeRefCounted<WebCore::LayerCompositingThread>::deref()
+{
+    if (derefBase())
+        static_cast<WebCore::LayerCompositingThread*>(this)->destroyOnCompositingThread();
 }
 
+} // namespace WTF
+
+
 #endif // USE(ACCELERATED_COMPOSITING)
 
 #endif