Title: [248532] trunk/Source/WebCore
Revision
248532
Author
[email protected]
Date
2019-08-12 10:27:51 -0700 (Mon, 12 Aug 2019)

Log Message

GPUBuffer seems to be ref'd / deref'd from multiple thread concurrently but is not ThreadSafeRefCounted
https://bugs.webkit.org/show_bug.cgi?id=200629

Reviewed by Geoffrey Garen.

Make sure GPUBuffer only gets ref'd / deref'd on the main thread, since it is not
ThreadSafeRefCounted.

* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::commandBufferCommitted):
(WebCore::GPUBuffer::commandBufferCompleted):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248531 => 248532)


--- trunk/Source/WebCore/ChangeLog	2019-08-12 17:13:55 UTC (rev 248531)
+++ trunk/Source/WebCore/ChangeLog	2019-08-12 17:27:51 UTC (rev 248532)
@@ -1,3 +1,17 @@
+2019-08-12  Chris Dumez  <[email protected]>
+
+        GPUBuffer seems to be ref'd / deref'd from multiple thread concurrently but is not ThreadSafeRefCounted
+        https://bugs.webkit.org/show_bug.cgi?id=200629
+
+        Reviewed by Geoffrey Garen.
+
+        Make sure GPUBuffer only gets ref'd / deref'd on the main thread, since it is not
+        ThreadSafeRefCounted.
+
+        * platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
+        (WebCore::GPUBuffer::commandBufferCommitted):
+        (WebCore::GPUBuffer::commandBufferCompleted):
+
 2019-08-12  Thibault Saunier  <[email protected]>
 
         [GStreamer][WebRTC] Handle broken data in the libwebrtc GStreamer decoders

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm (248531 => 248532)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm	2019-08-12 17:13:55 UTC (rev 248531)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm	2019-08-12 17:27:51 UTC (rev 248532)
@@ -34,6 +34,7 @@
 #import <_javascript_Core/ArrayBuffer.h>
 #import <Metal/Metal.h>
 #import <wtf/BlockObjCExceptions.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/CheckedArithmetic.h>
 #import <wtf/MainThread.h>
 
@@ -148,25 +149,26 @@
 #if USE(METAL)
 void GPUBuffer::commandBufferCommitted(MTLCommandBuffer *commandBuffer)
 {
+    ASSERT(isMainThread());
     ++m_numScheduledCommandBuffers;
 
-    auto protectedThis = makeRefPtr(this);
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer>) {
-        protectedThis->commandBufferCompleted();
-    }];
+    // Make sure |this| only gets ref'd / deref'd on the main thread since it is not ThreadSafeRefCounted.
+    [commandBuffer addCompletedHandler:makeBlockPtr([this, protectedThis = makeRef(*this)](id<MTLCommandBuffer>) mutable {
+        callOnMainThread([this, protectedThis = WTFMove(protectedThis)] {
+            commandBufferCompleted();
+        });
+    }).get()];
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
 void GPUBuffer::commandBufferCompleted()
 {
+    ASSERT(isMainThread());
     ASSERT(m_numScheduledCommandBuffers);
 
-    if (m_numScheduledCommandBuffers == 1 && state() == State::Mapped) {
-        callOnMainThread([this, protectedThis = makeRef(*this)] () {
-            runMappingCallback();
-        });
-    }
+    if (m_numScheduledCommandBuffers == 1 && state() == State::Mapped)
+        runMappingCallback();
 
     --m_numScheduledCommandBuffers;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to