Skip to content

Commit

Permalink
Unreviewed, reverting 274694@main.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269472

Causes crashes when multiple threads are rendering PDF pages

Reverted changeset:

"Deadlock under ~PluginView() with PDFPlugin."
https://bugs.webkit.org/show_bug.cgi?id=268536
https://commits.webkit.org/274694@main

Canonical link: https://commits.webkit.org/274738@main
  • Loading branch information
webkit-commit-queue authored and smfr committed Feb 15, 2024
1 parent 799678c commit c030c01
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 31 deletions.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFIncrementalLoader.h
Expand Up @@ -31,7 +31,6 @@
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/ThreadSafeWeakPtr.h>
#include <wtf/Threading.h>
#include <wtf/threads/BinarySemaphore.h>

OBJC_CLASS PDFDocument;

Expand Down Expand Up @@ -119,7 +118,6 @@ class PDFIncrementalLoader : public ThreadSafeRefCountedAndCanMakeThreadSafeWeak

RetainPtr<PDFDocument> m_backgroundThreadDocument;
RefPtr<Thread> m_pdfThread;
BinarySemaphore m_dataSemaphore;

Ref<PDFPluginStreamLoaderClient> m_streamLoaderClient;

Expand Down
13 changes: 5 additions & 8 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFIncrementalLoader.mm
Expand Up @@ -294,7 +294,6 @@
// we can force the PDFThread to complete quickly
if (m_pdfThread) {
unconditionalCompleteOutstandingRangeRequests();
m_dataSemaphore.signal();
m_pdfThread->waitForCompletion();
}
}
Expand Down Expand Up @@ -650,21 +649,19 @@ static void dataProviderReleaseInfoCallback(void* info)
return 0;
}

WTF::Semaphore dataSemaphore { 0 };
size_t bytesProvided = 0;
// Do not dispatch main runloop (again) and wait anymore if plugin has been destroyed.
if (plugin->hasBeenDestroyed())
return 0;

RunLoop::main().dispatch([this, protectedLoader = Ref { *this }, position, count, buffer, &bytesProvided] {
protectedLoader->getResourceBytesAtPosition(count, position, [this, count, buffer, &bytesProvided](const uint8_t* bytes, size_t bytesCount) {
RunLoop::main().dispatch([protectedLoader = Ref { *this }, position, count, buffer, &dataSemaphore, &bytesProvided] {
protectedLoader->getResourceBytesAtPosition(count, position, [count, buffer, &dataSemaphore, &bytesProvided](const uint8_t* bytes, size_t bytesCount) {
RELEASE_ASSERT(bytesCount <= count);
memcpy(buffer, bytes, bytesCount);
bytesProvided = bytesCount;
m_dataSemaphore.signal();
dataSemaphore.signal();
});
});

m_dataSemaphore.wait();
dataSemaphore.wait();

#if !LOG_DISABLED
decrementThreadsWaitingOnCallback();
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Expand Up @@ -227,7 +227,6 @@ class PDFPluginBase : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<PDF

private:
bool documentFinishedLoading() const { return m_documentFinishedLoading; }
bool hasBeenDestroyed() const { return m_hasBeenDestroyed; }
uint64_t streamedBytes() const { return m_streamedBytes; }
void ensureDataBufferLength(uint64_t);

Expand Down

0 comments on commit c030c01

Please sign in to comment.