WebKit Bugzilla
Attachment 339632 Details for
Bug 185339
: [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185339-20180505130544.patch (text/plain), 51.87 KB, created by
Yusuke Suzuki
on 2018-05-04 21:05:45 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-05-04 21:05:45 PDT
Size:
51.87 KB
patch
obsolete
>Subversion Revision: 231395 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index b2bea75c04d9732b15e5a64daf9d3a7cd65c2d11..7e8963758ca91dc7e120891814d1751c40ed209b 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,31 @@ >+2018-05-04 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >+ https://bugs.webkit.org/show_bug.cgi?id=185339 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds WTF::Semaphore, which is based on WTF::Lock and WTF::Condition. >+ >+ * WTF.xcodeproj/project.pbxproj: >+ * wtf/CMakeLists.txt: >+ * wtf/Semaphore.h: Added. >+ (WTF::Semaphore::Semaphore): >+ (WTF::Semaphore::signal): >+ (WTF::Semaphore::waitUntil): >+ (WTF::Semaphore::waitFor): >+ (WTF::Semaphore::wait): >+ * wtf/generic/WorkQueueGeneric.cpp: >+ (WorkQueue::platformInitialize): >+ * wtf/threads/BinarySemaphore.cpp: >+ (WTF::BinarySemaphore::waitUntil): >+ (WTF::BinarySemaphore::wait): Deleted. >+ * wtf/threads/BinarySemaphore.h: >+ (WTF::BinarySemaphore::waitFor): >+ (WTF::BinarySemaphore::wait): >+ Align the names of the functions to WTF::Condition. >+ Add BinarySemaphore::wait(), which is the same to waitUntil(WallTime::infinity()). >+ > 2018-05-04 Tim Horton <timothy_horton@apple.com> > > Shift to a lower-level framework for simplifying URLs >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 293ccf0b6b21fd8c6f1c02b808d9f81094b47a9a..888701c4acfc176bf8f317a5f2f810bc67782f75 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,69 @@ >+2018-05-04 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >+ https://bugs.webkit.org/show_bug.cgi?id=185339 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * fileapi/ThreadableBlobRegistry.cpp: >+ (WebCore::ThreadableBlobRegistry::blobSize): >+ * platform/cocoa/NetworkExtensionContentFilter.h: >+ * platform/cocoa/NetworkExtensionContentFilter.mm: >+ (WebCore::NetworkExtensionContentFilter::initialize): >+ (WebCore::NetworkExtensionContentFilter::willSendRequest): >+ (WebCore::NetworkExtensionContentFilter::responseReceived): >+ (WebCore::NetworkExtensionContentFilter::addData): >+ (WebCore::NetworkExtensionContentFilter::finishedAddingData): >+ (WebCore::NetworkExtensionContentFilter::handleDecision): >+ Use per-function BinarySemaphore instead of holding it in NetworkExtensionContentFilter's field. >+ >+ * platform/glib/FileMonitorGLib.cpp: >+ (WebCore::FileMonitor::FileMonitor): >+ (WebCore::FileMonitor::~FileMonitor): >+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: >+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: >+ (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): >+ (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): >+ (WebCore::MediaPlayerPrivateAVFoundationObjC::waitForVideoOutputMediaDataWillChange): >+ (WebCore::MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange): >+ Use BinarySemaphore. And remove unused dispatch_semaphore_t. >+ >+ * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: >+ * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: >+ (-[WebAVStreamDataParserListener streamDataParserWillProvideContentKeyRequestInitializationData:forTrackID:]): >+ (-[WebAVStreamDataParserListener streamDataParser:didProvideContentKeyRequestInitializationData:forTrackID:]): >+ (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): >+ (WebCore::SourceBufferPrivateAVFObjC::~SourceBufferPrivateAVFObjC): >+ (WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID): >+ (WebCore::SourceBufferPrivateAVFObjC::abort): >+ (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): >+ (WebCore::SourceBufferPrivateAVFObjC::setCDMInstance): >+ Use Box<Semaphore> and Box<BinarySemaphore>. >+ >+ * platform/graphics/cocoa/WebCoreDecompressionSession.h: >+ * platform/graphics/cocoa/WebCoreDecompressionSession.mm: >+ (WebCore::WebCoreDecompressionSession::WebCoreDecompressionSession): >+ Remove unused dispatch_semaphore_t. >+ >+ * platform/network/cf/ResourceHandleCFNet.cpp: >+ (WebCore::ResourceHandle::platformLoadResourceSynchronously): >+ * platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp: >+ (WebCore::getRunLoop): >+ (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest): >+ (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveResponse): >+ (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::willCacheResponse): >+ (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToProtectionSpace): >+ * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h: >+ * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm: >+ (-[WebCoreResourceHandleAsOperationQueueDelegate initWithHandle:messageQueue:]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate detachHandle]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate dealloc]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate connection:canAuthenticateAgainstProtectionSpace:]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveResponse:]): >+ (-[WebCoreResourceHandleAsOperationQueueDelegate connection:willCacheResponse:]): >+ Use BinarySemaphore instead. >+ > 2018-05-02 Dean Jackson <dino@apple.com> > > Use IOSurfaces for CoreImage operations where possible >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 6bc61b61b4fa0246738dc1fa2eae9f8e23d6f533..c91d10095fa7e398aac107db318c8ebe6c2852d9 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,25 @@ >+2018-05-04 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >+ https://bugs.webkit.org/show_bug.cgi?id=185339 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Platform/IPC/Connection.cpp: >+ (IPC::Connection::SyncMessageState::wait): >+ * Shared/mac/SecItemShim.cpp: >+ (WebKit::sendSecItemRequest): >+ Use BinarySemaphore. >+ >+ * UIProcess/ResourceLoadStatisticsPersistentStorage.cpp: >+ (WebKit::ResourceLoadStatisticsPersistentStorage::finishAllPendingWorkSynchronously): >+ * UIProcess/WebStorage/StorageManager.cpp: >+ (WebKit::StorageManager::applicationWillTerminate): >+ * UIProcess/ios/WKActionSheetAssistant.mm: >+ (appLinkForURL): >+ Use BinarySemaphore to wait for async completion handler. We also fix memory leak >+ since the old code does not call dispatch_release for the used semaphore. >+ > 2018-05-04 Tim Horton <timothy_horton@apple.com> > > Shift to a lower-level framework for simplifying URLs >diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj >index 1a38f1986e86d6bb9424e17974eb28ea34d6fce2..7e616eb344494355865ab7a8595831e415dcb9c6 100644 >--- a/Source/WTF/WTF.xcodeproj/project.pbxproj >+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj >@@ -619,6 +619,7 @@ > E38D6E261F5522E300A75CC4 /* StringBuilderJSON.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilderJSON.cpp; sourceTree = "<group>"; }; > E3A32BC21FC830E2007D7E76 /* JSValueMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSValueMalloc.cpp; sourceTree = "<group>"; }; > E3A32BC31FC830E2007D7E76 /* JSValueMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSValueMalloc.h; sourceTree = "<group>"; }; >+ E3C21D8B209D5C70006CC078 /* Semaphore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Semaphore.h; sourceTree = "<group>"; }; > E3E158251EADA53C004A079D /* SystemFree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemFree.h; sourceTree = "<group>"; }; > E4A0AD371A96245500536DF6 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = "<group>"; }; > E4A0AD381A96245500536DF6 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = "<group>"; }; >@@ -1046,6 +1047,7 @@ > 0F66B2841DC97BAB004A1D3F /* Seconds.cpp */, > 0F66B2851DC97BAB004A1D3F /* Seconds.h */, > A8A47306151A825B004123FF /* SegmentedVector.h */, >+ E3C21D8B209D5C70006CC078 /* Semaphore.h */, > A8A47307151A825B004123FF /* SentinelLinkedList.h */, > A8A4731A151A825B004123FF /* SetForScope.h */, > A8A47308151A825B004123FF /* SHA1.cpp */, >diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt >index 4890297e9769d9ac8a2e32c14117361253da8bfe..80976cb0b63aab57b99eae7d45563b7feeb6b5fd 100644 >--- a/Source/WTF/wtf/CMakeLists.txt >+++ b/Source/WTF/wtf/CMakeLists.txt >@@ -196,6 +196,7 @@ set(WTF_PUBLIC_HEADERS > ScopedLambda.h > Seconds.h > SegmentedVector.h >+ Semaphore.h > SentinelLinkedList.h > SetForScope.h > SharedTask.h >diff --git a/Source/WTF/wtf/Semaphore.h b/Source/WTF/wtf/Semaphore.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1ee5270f818ed01b934df8f9c0113ddc862f1525 >--- /dev/null >+++ b/Source/WTF/wtf/Semaphore.h >@@ -0,0 +1,81 @@ >+/* >+ * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include <wtf/Condition.h> >+#include <wtf/Lock.h> >+#include <wtf/Noncopyable.h> >+ >+namespace WTF { >+ >+class Semaphore { >+ WTF_MAKE_NONCOPYABLE(Semaphore); >+ WTF_MAKE_FAST_ALLOCATED; >+public: >+ constexpr Semaphore(unsigned value) >+ : m_value(value) >+ { >+ } >+ >+ void signal() >+ { >+ auto locker = holdLock(m_lock); >+ m_value++; >+ m_condition.notifyOne(); >+ } >+ >+ bool waitUntil(const TimeWithDynamicClockType& timeout) >+ { >+ auto locker = holdLock(m_lock); >+ bool satisfied = m_condition.waitUntil(m_lock, timeout, >+ [&] { >+ return m_value; >+ }); >+ if (satisfied) >+ --m_value; >+ return satisfied; >+ } >+ >+ bool waitFor(Seconds relativeTimeout) >+ { >+ return waitUntil(MonotonicTime::now() + relativeTimeout); >+ } >+ >+ void wait() >+ { >+ waitUntil(ParkingLot::Time::infinity()); >+ } >+ >+private: >+ unsigned m_value { 0 }; >+ Lock m_lock; >+ Condition m_condition; >+}; >+ >+ >+} // namespace WTF >+ >+using WTF::Semaphore; >diff --git a/Source/WTF/wtf/generic/WorkQueueGeneric.cpp b/Source/WTF/wtf/generic/WorkQueueGeneric.cpp >index e0591644aaa27e5556c637538ea8e8192c5aa9a6..3c0492ff54eb0d75020aac74e967b6958be7c5ea 100644 >--- a/Source/WTF/wtf/generic/WorkQueueGeneric.cpp >+++ b/Source/WTF/wtf/generic/WorkQueueGeneric.cpp >@@ -42,7 +42,7 @@ void WorkQueue::platformInitialize(const char* name, Type, QOS) > semaphore.signal(); > m_runLoop->run(); > })->detach(); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > > void WorkQueue::platformInvalidate() >diff --git a/Source/WTF/wtf/threads/BinarySemaphore.cpp b/Source/WTF/wtf/threads/BinarySemaphore.cpp >index e2f6ded79f4201063a0b481239e912f22f587e83..18056822c3d9bcd337f13d37fcdc8ef92bd6ccf0 100644 >--- a/Source/WTF/wtf/threads/BinarySemaphore.cpp >+++ b/Source/WTF/wtf/threads/BinarySemaphore.cpp >@@ -35,7 +35,7 @@ void BinarySemaphore::signal() > m_condition.notifyOne(); > } > >-bool BinarySemaphore::wait(TimeWithDynamicClockType absoluteTime) >+bool BinarySemaphore::waitUntil(const TimeWithDynamicClockType& absoluteTime) > { > auto locker = holdLock(m_lock); > bool satisfied = m_condition.waitUntil(m_lock, absoluteTime, [&] { return m_isSet; }); >diff --git a/Source/WTF/wtf/threads/BinarySemaphore.h b/Source/WTF/wtf/threads/BinarySemaphore.h >index fd59d5aa2babc22dabf55655e6601f648490ede2..d5b738f5f3c29c2292cae8c50b509b86a46e68db 100644 >--- a/Source/WTF/wtf/threads/BinarySemaphore.h >+++ b/Source/WTF/wtf/threads/BinarySemaphore.h >@@ -35,11 +35,22 @@ namespace WTF { > > class BinarySemaphore { > WTF_MAKE_NONCOPYABLE(BinarySemaphore); >+ WTF_MAKE_FAST_ALLOCATED; > public: >- BinarySemaphore() = default; >+ constexpr BinarySemaphore() = default; > > WTF_EXPORT_PRIVATE void signal(); >- WTF_EXPORT_PRIVATE bool wait(TimeWithDynamicClockType); >+ WTF_EXPORT_PRIVATE bool waitUntil(const TimeWithDynamicClockType&); >+ >+ bool waitFor(Seconds relativeTimeout) >+ { >+ return waitUntil(MonotonicTime::now() + relativeTimeout); >+ } >+ >+ void wait() >+ { >+ waitUntil(ParkingLot::Time::infinity()); >+ } > > private: > bool m_isSet { false }; >diff --git a/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp >index b6c57a31d8c2b5133ebbc938d349201640127893..5bc9baf782796ba433d7e829c10af67717aa4390 100644 >--- a/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp >+++ b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp >@@ -150,7 +150,7 @@ unsigned long long ThreadableBlobRegistry::blobSize(const URL& url) > resultSize = blobRegistry().blobSize(url); > semaphore.signal(); > }); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > return resultSize; > } >diff --git a/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h b/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h >index 983b7035b700ec18fb93ad1a3248d1115e3d9d21..2106c2ba9b86ac020b407010e913239bd42590ef 100644 >--- a/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h >+++ b/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h >@@ -64,7 +64,6 @@ class NetworkExtensionContentFilter final : public PlatformContentFilter { > void handleDecision(NEFilterSourceStatus, NSData *replacementData); > > OSObjectPtr<dispatch_queue_t> m_queue; >- OSObjectPtr<dispatch_semaphore_t> m_semaphore; > RetainPtr<NSData> m_replacementData; > RetainPtr<NEFilterSource> m_neFilterSource; > }; >diff --git a/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm b/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm >index 7d0d25ee29d1c6a30b2344fa25412f5f359874c0..a6c1b361a729a030c280f061858885e5aae14ccb 100644 >--- a/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm >+++ b/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm >@@ -38,6 +38,7 @@ > #import <objc/runtime.h> > #import <pal/spi/cocoa/NEFilterSourceSPI.h> > #import <wtf/SoftLinking.h> >+#import <wtf/threads/BinarySemaphore.h> > > SOFT_LINK_FRAMEWORK_OPTIONAL(NetworkExtension); > SOFT_LINK_CLASS_OPTIONAL(NetworkExtension, NEFilterSource); >@@ -70,10 +71,8 @@ std::unique_ptr<NetworkExtensionContentFilter> NetworkExtensionContentFilter::cr > void NetworkExtensionContentFilter::initialize(const URL* url) > { > ASSERT(!m_queue); >- ASSERT(!m_semaphore); > ASSERT(!m_neFilterSource); > m_queue = adoptOSObject(dispatch_queue_create("WebKit NetworkExtension Filtering", DISPATCH_QUEUE_SERIAL)); >- m_semaphore = adoptOSObject(dispatch_semaphore_create(0)); > ASSERT_UNUSED(url, !url); > m_neFilterSource = adoptNS([allocNEFilterSourceInstance() initWithDecisionQueue:m_queue.get()]); > #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) >@@ -100,17 +99,19 @@ void NetworkExtensionContentFilter::willSendRequest(ResourceRequest& request, co > return; > } > >+ BinarySemaphore semaphore; > RetainPtr<NSString> modifiedRequestURLString; >- [m_neFilterSource willSendRequest:request.nsURLRequest(DoNotUpdateHTTPBody) decisionHandler:[this, &modifiedRequestURLString](NEFilterSourceStatus status, NSDictionary *decisionInfo) { >+ [m_neFilterSource willSendRequest:request.nsURLRequest(DoNotUpdateHTTPBody) decisionHandler:[this, &modifiedRequestURLString, &semaphore](NEFilterSourceStatus status, NSDictionary *decisionInfo) { > modifiedRequestURLString = decisionInfo[NEFilterSourceOptionsRedirectURL]; > ASSERT(!modifiedRequestURLString || [modifiedRequestURLString isKindOfClass:[NSString class]]); > handleDecision(status, replacementDataFromDecisionInfo(decisionInfo)); >+ semaphore.signal(); > }]; > > // FIXME: We have to block here since DocumentLoader expects to have a > // blocked/not blocked answer from the filter immediately after calling > // addData(). We should find a way to make this asynchronous. >- dispatch_semaphore_wait(m_semaphore.get(), DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > > if (!modifiedRequestURLString) > return; >@@ -131,40 +132,46 @@ void NetworkExtensionContentFilter::responseReceived(const ResourceResponse& res > return; > } > >- [m_neFilterSource receivedResponse:response.nsURLResponse() decisionHandler:[this](NEFilterSourceStatus status, NSDictionary *decisionInfo) { >+ BinarySemaphore semaphore; >+ [m_neFilterSource receivedResponse:response.nsURLResponse() decisionHandler:[this, &semaphore](NEFilterSourceStatus status, NSDictionary *decisionInfo) { > handleDecision(status, replacementDataFromDecisionInfo(decisionInfo)); >+ semaphore.signal(); > }]; > > // FIXME: We have to block here since DocumentLoader expects to have a > // blocked/not blocked answer from the filter immediately after calling > // addData(). We should find a way to make this asynchronous. >- dispatch_semaphore_wait(m_semaphore.get(), DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > } > > void NetworkExtensionContentFilter::addData(const char* data, int length) > { > RetainPtr<NSData> copiedData { [NSData dataWithBytes:(void*)data length:length] }; > >- [m_neFilterSource receivedData:copiedData.get() decisionHandler:[this](NEFilterSourceStatus status, NSDictionary *decisionInfo) { >+ BinarySemaphore semaphore; >+ [m_neFilterSource receivedData:copiedData.get() decisionHandler:[this, &semaphore](NEFilterSourceStatus status, NSDictionary *decisionInfo) { > handleDecision(status, replacementDataFromDecisionInfo(decisionInfo)); >+ semaphore.signal(); > }]; > > // FIXME: We have to block here since DocumentLoader expects to have a > // blocked/not blocked answer from the filter immediately after calling > // addData(). We should find a way to make this asynchronous. >- dispatch_semaphore_wait(m_semaphore.get(), DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > } > > void NetworkExtensionContentFilter::finishedAddingData() > { >- [m_neFilterSource finishedLoadingWithDecisionHandler:[this](NEFilterSourceStatus status, NSDictionary *decisionInfo) { >+ BinarySemaphore semaphore; >+ [m_neFilterSource finishedLoadingWithDecisionHandler:[this, &semaphore](NEFilterSourceStatus status, NSDictionary *decisionInfo) { > handleDecision(status, replacementDataFromDecisionInfo(decisionInfo)); >+ semaphore.signal(); > }]; > > // FIXME: We have to block here since DocumentLoader expects to have a > // blocked/not blocked answer from the filter immediately after calling > // finishedAddingData(). We should find a way to make this asynchronous. >- dispatch_semaphore_wait(m_semaphore.get(), DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > } > > Ref<SharedBuffer> NetworkExtensionContentFilter::replacementData() const >@@ -215,7 +222,6 @@ void NetworkExtensionContentFilter::handleDecision(NEFilterSourceStatus status, > if (!needsMoreData()) > LOG(ContentFiltering, "NetworkExtensionContentFilter stopped buffering with status %zd and replacement data length %zu.\n", status, replacementData.length); > #endif >- dispatch_semaphore_signal(m_semaphore.get()); > } > > } // namespace WebCore >diff --git a/Source/WebCore/platform/glib/FileMonitorGLib.cpp b/Source/WebCore/platform/glib/FileMonitorGLib.cpp >index bb695a927a397d3ae02849cbf09c991c26d95b72..463f3276c24e251beb4aa08b0b98986e8cc96923 100644 >--- a/Source/WebCore/platform/glib/FileMonitorGLib.cpp >+++ b/Source/WebCore/platform/glib/FileMonitorGLib.cpp >@@ -60,7 +60,7 @@ FileMonitor::FileMonitor(const String& path, Ref<WorkQueue>&& handlerQueue, WTF: > createPlatformMonitor(); > semaphore.signal(); > }); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > > FileMonitor::~FileMonitor() >@@ -74,7 +74,7 @@ FileMonitor::~FileMonitor() > m_platformMonitor = nullptr; > semaphore.signal(); > }); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > > void FileMonitor::fileChangedCallback(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent event, FileMonitor* monitor) >diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h b/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h >index f464703cf97f48a491eb0c90597b3c67adf1fb14..8857d8b472b3e449fc9d64ebd315b80a9cd78246 100644 >--- a/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h >+++ b/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h >@@ -32,6 +32,7 @@ > #include "MediaPlayerPrivateAVFoundation.h" > #include <wtf/Function.h> > #include <wtf/HashMap.h> >+#include <wtf/threads/BinarySemaphore.h> > > OBJC_CLASS AVAssetImageGenerator; > OBJC_CLASS AVAssetResourceLoadingRequest; >@@ -359,7 +360,7 @@ class MediaPlayerPrivateAVFoundationObjC : public MediaPlayerPrivateAVFoundation > RetainPtr<WebCoreAVFPullDelegate> m_videoOutputDelegate; > RetainPtr<CVPixelBufferRef> m_lastPixelBuffer; > RetainPtr<CGImageRef> m_lastImage; >- dispatch_semaphore_t m_videoOutputSemaphore; >+ BinarySemaphore m_videoOutputSemaphore; > std::unique_ptr<VideoTextureCopierCV> m_videoTextureCopier; > #endif > >diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm b/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm >index 2a96a8b146f30f4eee890df3be3a9aa807f5df96..a5266bbff3cb8b7c88cac9ceac145d4ed494ee77 100644 >--- a/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm >+++ b/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm >@@ -348,7 +348,6 @@ @end > #if HAVE(AVFOUNDATION_VIDEO_OUTPUT) > @interface WebCoreAVFPullDelegate : NSObject<AVPlayerItemOutputPullDelegate> { > MediaPlayerPrivateAVFoundationObjC *m_callback; >- dispatch_semaphore_t m_semaphore; > } > - (id)initWithCallback:(MediaPlayerPrivateAVFoundationObjC *)callback; > - (void)setCallback:(MediaPlayerPrivateAVFoundationObjC*)callback; >@@ -492,7 +491,6 @@ MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC(MediaPlay > , m_haveCheckedPlayability(false) > #if HAVE(AVFOUNDATION_VIDEO_OUTPUT) > , m_videoOutputDelegate(adoptNS([[WebCoreAVFPullDelegate alloc] initWithCallback:this])) >- , m_videoOutputSemaphore(nullptr) > #endif > #if HAVE(AVFOUNDATION_LOADER_DELEGATE) > , m_loaderDelegate(adoptNS([[WebCoreAVFLoaderDelegate alloc] initWithCallback:this])) >@@ -527,8 +525,6 @@ MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC() > #if HAVE(AVFOUNDATION_VIDEO_OUTPUT) > [m_videoOutputDelegate setCallback:0]; > [m_videoOutput setDelegate:nil queue:0]; >- if (m_videoOutputSemaphore) >- dispatch_release(m_videoOutputSemaphore); > #endif > > if (m_videoLayer) >@@ -2369,21 +2365,17 @@ NativeImagePtr MediaPlayerPrivateAVFoundationObjC::nativeImageForCurrentTime() > > void MediaPlayerPrivateAVFoundationObjC::waitForVideoOutputMediaDataWillChange() > { >- if (!m_videoOutputSemaphore) >- m_videoOutputSemaphore = dispatch_semaphore_create(0); >- > [m_videoOutput requestNotificationOfMediaDataChangeWithAdvanceInterval:0]; > > // Wait for 1 second. >- long result = dispatch_semaphore_wait(m_videoOutputSemaphore, dispatch_time(0, 1 * NSEC_PER_SEC)); >- >- if (result) >+ bool satisfied = m_videoOutputSemaphore.waitFor(1_s); >+ if (!satisfied) > ERROR_LOG(LOGIDENTIFIER, "timed out"); > } > > void MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange(AVPlayerItemVideoOutputType *) > { >- dispatch_semaphore_signal(m_videoOutputSemaphore); >+ m_videoOutputSemaphore.signal(); > } > > #endif >diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h >index 11f2fa92d2e6c2cee206e586e6d56a400c419f4a..5ea36b715ab81f8843339d383d32a0a1f633a473 100644 >--- a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h >+++ b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h >@@ -29,7 +29,7 @@ > > #include "SourceBufferPrivate.h" > #include <dispatch/group.h> >-#include <dispatch/semaphore.h> >+#include <wtf/Box.h> > #include <wtf/Deque.h> > #include <wtf/HashMap.h> > #include <wtf/MediaTime.h> >@@ -39,6 +39,7 @@ > #include <wtf/Vector.h> > #include <wtf/WeakPtr.h> > #include <wtf/text/AtomicString.h> >+#include <wtf/threads/BinarySemaphore.h> > > OBJC_CLASS AVAsset; > OBJC_CLASS AVStreamDataParser; >@@ -90,7 +91,7 @@ class SourceBufferPrivateAVFObjC final : public SourceBufferPrivate { > void didProvideMediaDataForTrackID(int trackID, CMSampleBufferRef, const String& mediaType, unsigned flags); > void didReachEndOfTrackWithTrackID(int trackID, const String& mediaType); > void willProvideContentKeyRequestInitializationDataForTrackID(int trackID); >- void didProvideContentKeyRequestInitializationDataForTrackID(NSData*, int trackID, OSObjectPtr<dispatch_semaphore_t>); >+ void didProvideContentKeyRequestInitializationDataForTrackID(NSData*, int trackID, Box<BinarySemaphore>); > > bool processCodedFrame(int trackID, CMSampleBufferRef, const String& mediaType); > >@@ -177,7 +178,7 @@ class SourceBufferPrivateAVFObjC final : public SourceBufferPrivate { > RetainPtr<WebAVStreamDataParserListener> m_delegate; > RetainPtr<WebAVSampleBufferErrorListener> m_errorListener; > RetainPtr<NSError> m_hdcpError; >- OSObjectPtr<dispatch_semaphore_t> m_hasSessionSemaphore; >+ Box<BinarySemaphore> m_hasSessionSemaphore; > OSObjectPtr<dispatch_group_t> m_isAppendingGroup; > RefPtr<WebCoreDecompressionSession> m_decompressionSession; > >diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm >index 54cfb8eab733e2e53f493b28666057d604c25299..7325d777c81a06e6e6d0366cb9e450bb839d15fc 100644 >--- a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm >+++ b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm >@@ -55,6 +55,7 @@ > #import <wtf/BlockObjCExceptions.h> > #import <wtf/HashCountedSet.h> > #import <wtf/MainThread.h> >+#import <wtf/Semaphore.h> > #import <wtf/SoftLinking.h> > #import <wtf/WeakPtr.h> > #import <wtf/text/AtomicString.h> >@@ -109,11 +110,11 @@ @end > > @interface WebAVStreamDataParserListener : NSObject<AVStreamDataParserOutputHandling> { > WeakPtr<WebCore::SourceBufferPrivateAVFObjC> _parent; >- OSObjectPtr<dispatch_semaphore_t> _abortSemaphore; >+ Box<Semaphore> _abortSemaphore; > AVStreamDataParser* _parser; > } > @property (assign) WeakPtr<WebCore::SourceBufferPrivateAVFObjC> parent; >-@property (assign) OSObjectPtr<dispatch_semaphore_t> abortSemaphore; >+@property (assign) Box<Semaphore> abortSemaphore; > - (id)initWithParser:(AVStreamDataParser*)parser parent:(WeakPtr<WebCore::SourceBufferPrivateAVFObjC>)parent; > @end > >@@ -207,19 +208,19 @@ - (void)streamDataParserWillProvideContentKeyRequestInitializationData:(AVStream > > // We must call synchronously to the main thread, as the AVStreamSession must be associated > // with the streamDataParser before the delegate method returns. >- OSObjectPtr<dispatch_semaphore_t> respondedSemaphore = adoptOSObject(dispatch_semaphore_create(0)); >+ Box<BinarySemaphore> respondedSemaphore = Box<BinarySemaphore>::create(); > callOnMainThread([parent = _parent, trackID, respondedSemaphore]() { > if (parent) > parent->willProvideContentKeyRequestInitializationDataForTrackID(trackID); >- dispatch_semaphore_signal(respondedSemaphore.get()); >+ respondedSemaphore->signal(); > }); > > while (true) { >- if (!dispatch_semaphore_wait(respondedSemaphore.get(), dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC * 100))) >+ if (respondedSemaphore->waitFor(100_ms)) > return; > >- if (!dispatch_semaphore_wait(_abortSemaphore.get(), dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC * 100))) { >- dispatch_semaphore_signal(_abortSemaphore.get()); >+ if (_abortSemaphore->waitFor(100_ms)) { >+ _abortSemaphore->signal(); > return; > } > } >@@ -229,18 +230,18 @@ - (void)streamDataParser:(AVStreamDataParser *)streamDataParser didProvideConten > { > ASSERT_UNUSED(streamDataParser, streamDataParser == _parser); > >- OSObjectPtr<dispatch_semaphore_t> hasSessionSemaphore = adoptOSObject(dispatch_semaphore_create(0)); >+ Box<BinarySemaphore> hasSessionSemaphore = Box<BinarySemaphore>::create(); > callOnMainThread([parent = _parent, protectedInitData = RetainPtr<NSData>(initData), trackID, hasSessionSemaphore] { > if (parent) > parent->didProvideContentKeyRequestInitializationDataForTrackID(protectedInitData.get(), trackID, hasSessionSemaphore); > }); > > while (true) { >- if (!dispatch_semaphore_wait(hasSessionSemaphore.get(), dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC * 100))) >+ if (hasSessionSemaphore->waitFor(100_ms)) > return; > >- if (!dispatch_semaphore_wait(_abortSemaphore.get(), dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC * 100))) { >- dispatch_semaphore_signal(_abortSemaphore.get()); >+ if (_abortSemaphore->waitFor(100_ms)) { >+ _abortSemaphore->signal(); > return; > } > } >@@ -509,7 +510,7 @@ SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC(MediaSourcePrivateAVFObjC > , m_mediaSource(parent) > { > CMNotificationCenterAddListener(CMNotificationCenterGetDefaultLocalCenter(), this, bufferWasConsumedCallback, kCMSampleBufferConsumerNotification_BufferConsumed, nullptr, 0); >- m_delegate.get().abortSemaphore = adoptOSObject(dispatch_semaphore_create(0)); >+ m_delegate.get().abortSemaphore = Box<Semaphore>::create(0); > } > > SourceBufferPrivateAVFObjC::~SourceBufferPrivateAVFObjC() >@@ -521,7 +522,7 @@ SourceBufferPrivateAVFObjC::~SourceBufferPrivateAVFObjC() > CMNotificationCenterRemoveListener(CMNotificationCenterGetDefaultLocalCenter(), this, bufferWasConsumedCallback, kCMSampleBufferConsumerNotification_BufferConsumed, nullptr); > > if (m_hasSessionSemaphore) >- dispatch_semaphore_signal(m_hasSessionSemaphore.get()); >+ m_hasSessionSemaphore->signal(); > } > > void SourceBufferPrivateAVFObjC::didParseStreamDataAsAsset(AVAsset* asset) >@@ -651,7 +652,7 @@ void SourceBufferPrivateAVFObjC::willProvideContentKeyRequestInitializationDataF > #endif > } > >-void SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID(NSData* initData, int trackID, OSObjectPtr<dispatch_semaphore_t> hasSessionSemaphore) >+void SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID(NSData* initData, int trackID, Box<BinarySemaphore> hasSessionSemaphore) > { > if (!m_mediaSource) > return; >@@ -664,10 +665,10 @@ void SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataFo > m_mediaSource->sourceBufferKeyNeeded(this, initDataArray.get()); > if (auto session = m_mediaSource->player()->cdmSession()) { > session->addParser(m_parser.get()); >- dispatch_semaphore_signal(hasSessionSemaphore.get()); >+ hasSessionSemaphore->signal(); > } else { > if (m_hasSessionSemaphore) >- dispatch_semaphore_signal(m_hasSessionSemaphore.get()); >+ m_hasSessionSemaphore->signal(); > m_hasSessionSemaphore = hasSessionSemaphore; > } > #endif >@@ -742,12 +743,12 @@ void SourceBufferPrivateAVFObjC::abort() > // were asked to abort, and that cancels all outstanding append operations. Without cancelling this > // semaphore, the m_isAppendingGroup wait operation will deadlock. > if (m_hasSessionSemaphore) >- dispatch_semaphore_signal(m_hasSessionSemaphore.get()); >- dispatch_semaphore_signal(m_delegate.get().abortSemaphore.get()); >+ m_hasSessionSemaphore->signal(); >+ m_delegate.get().abortSemaphore->signal(); > dispatch_group_wait(m_isAppendingGroup.get(), DISPATCH_TIME_FOREVER); > m_appendWeakFactory.revokeAll(); > m_delegate.get().parent = m_appendWeakFactory.createWeakPtr(*this); >- m_delegate.get().abortSemaphore = adoptOSObject(dispatch_semaphore_create(0)); >+ m_delegate.get().abortSemaphore = Box<Semaphore>::create(0); > } > > void SourceBufferPrivateAVFObjC::resetParserState() >@@ -899,7 +900,7 @@ void SourceBufferPrivateAVFObjC::setCDMSession(CDMSessionMediaSourceAVFObjC* ses > if (m_session) { > m_session->addSourceBuffer(this); > if (m_hasSessionSemaphore) { >- dispatch_semaphore_signal(m_hasSessionSemaphore.get()); >+ m_hasSessionSemaphore->signal(); > m_hasSessionSemaphore = nullptr; > } > >@@ -934,7 +935,7 @@ void SourceBufferPrivateAVFObjC::setCDMInstance(CDMInstance* instance) > if (m_cdmInstance) { > [m_cdmInstance->contentKeySession() addContentKeyRecipient:m_parser.get()]; > if (m_hasSessionSemaphore) { >- dispatch_semaphore_signal(m_hasSessionSemaphore.get()); >+ m_hasSessionSemaphore->signal(); > m_hasSessionSemaphore = nullptr; > } > } >diff --git a/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h b/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h >index f196c2016ccf730a71012b722bad9d5fd4a75e83..837d612eff924fa3e143a70bfc6f2d63f5554e88 100644 >--- a/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h >+++ b/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h >@@ -117,7 +117,6 @@ class WebCoreDecompressionSession : public ThreadSafeRefCounted<WebCoreDecompres > RetainPtr<CMTimebaseRef> m_timebase; > OSObjectPtr<dispatch_queue_t> m_decompressionQueue; > OSObjectPtr<dispatch_queue_t> m_enqueingQueue; >- OSObjectPtr<dispatch_semaphore_t> m_hasAvailableImageSemaphore; > OSObjectPtr<dispatch_source_t> m_timerSource; > std::function<void()> m_notificationCallback; > std::function<void()> m_hasAvailableFrameCallback; >diff --git a/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm b/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm >index 3abcbdcd8f291ac9c5e60ac64fff2945e1f91eef..64f6dfecb0167171660b8330a0a2766f7ce7c8c0 100644 >--- a/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm >+++ b/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm >@@ -53,7 +53,6 @@ WebCoreDecompressionSession::WebCoreDecompressionSession(Mode mode) > : m_mode(mode) > , m_decompressionQueue(adoptOSObject(dispatch_queue_create("WebCoreDecompressionSession Decompression Queue", DISPATCH_QUEUE_SERIAL))) > , m_enqueingQueue(adoptOSObject(dispatch_queue_create("WebCoreDecompressionSession Enqueueing Queue", DISPATCH_QUEUE_SERIAL))) >- , m_hasAvailableImageSemaphore(adoptOSObject(dispatch_semaphore_create(0))) > { > } > >diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp b/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp >index 97864fe5bf9e92838cd718e9351e168184862e7c..e711a6718040594eae676c2e95651201d6ffe159 100644 >--- a/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp >+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp >@@ -585,7 +585,7 @@ void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* contex > while (true) > CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1E30, true); > }); >- sem.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ sem.wait(); > } > CFURLConnectionScheduleWithRunLoop(handle->connection(), runLoop, kCFRunLoopDefaultMode); > CFURLConnectionScheduleDownloadWithRunLoop(handle->connection(), runLoop, kCFRunLoopDefaultMode); >diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp >index 95e7ffd5786f0baa25a49b21d29196c38bbcd584..dad9010f9570ebc567633543fd1fc502f8469b99 100644 >--- a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp >+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp >@@ -119,7 +119,7 @@ static CFRunLoopRef getRunLoop() > while (true) > CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1E30, true); > }); >- sem.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ sem.wait(); > } > > return runLoop; >@@ -172,7 +172,7 @@ CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSen > m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); > else > callOnMainThread(WTFMove(work)); >- m_semaphore.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ m_semaphore.wait(); > > return m_requestResult.leakRef(); > } >@@ -210,7 +210,7 @@ void ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveResponse > m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); > else > callOnMainThread(WTFMove(work)); >- m_semaphore.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ m_semaphore.wait(); > } > > void ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveData(CFDataRef data, CFIndex originalLength) >@@ -314,7 +314,7 @@ CFCachedURLResponseRef ResourceHandleCFURLConnectionDelegateWithOperationQueue:: > m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); > else > callOnMainThread(WTFMove(work)); >- m_semaphore.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ m_semaphore.wait(); > return m_cachedResponseResult.leakRef(); > } > >@@ -383,7 +383,7 @@ Boolean ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToPro > m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); > else > callOnMainThread(WTFMove(work)); >- m_semaphore.wait(TimeWithDynamicClockType(WallTime::infinity())); >+ m_semaphore.wait(); > return m_boolResult; > } > >diff --git a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h >index 48354264e68a2e095b87d53d93e5a9e20649cc45..3eda27ea8a217c620f9a3eda75b0ef680d81423a 100644 >--- a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h >+++ b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h >@@ -31,6 +31,7 @@ > #include <wtf/MessageQueue.h> > #include <wtf/RetainPtr.h> > #include <wtf/SchedulePair.h> >+#include <wtf/threads/BinarySemaphore.h> > > namespace WebCore { > class ResourceHandle; >@@ -40,7 +41,7 @@ class ResourceHandle; > WebCore::ResourceHandle* m_handle; > > // Synchronous delegates on operation queue wait until main thread sends an asynchronous response. >- dispatch_semaphore_t m_semaphore; >+ BinarySemaphore m_semaphore; > MessageQueue<Function<void()>>* m_messageQueue; > RetainPtr<NSURLRequest> m_requestResult; > Lock m_mutex; >diff --git a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm >index a5ab3675462dc6680bb99453166808086423440b..dc98cae96f3717f8263c29c599687c6715929923 100644 >--- a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm >+++ b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm >@@ -89,7 +89,6 @@ - (id)initWithHandle:(ResourceHandle*)handle messageQueue:(MessageQueue<Function > if (auto* pairs = m_handle->context()->scheduledRunLoopPairs()) > m_scheduledPairs = *pairs; > } >- m_semaphore = dispatch_semaphore_create(0); > m_messageQueue = messageQueue; > > return self; >@@ -105,12 +104,11 @@ - (void)detachHandle > m_requestResult = nullptr; > m_cachedResponseResult = nullptr; > m_boolResult = NO; >- dispatch_semaphore_signal(m_semaphore); // OK to signal even if we are not waiting. >+ m_semaphore.signal(); // OK to signal even if we are not waiting. > } > > - (void)dealloc > { >- dispatch_release(m_semaphore); > [super dealloc]; > } > >@@ -136,18 +134,18 @@ - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSUR > auto work = [self, protectedSelf, newRequest = retainPtr(newRequest), redirectResponse = retainPtr(redirectResponse)] () mutable { > if (!m_handle) { > m_requestResult = nullptr; >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > return; > } > > m_handle->willSendRequest(newRequest.get(), redirectResponse.get(), [self, protectedSelf = WTFMove(protectedSelf)](ResourceRequest&& request) { > m_requestResult = request.nsURLRequest(UpdateHTTPBody); >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > }); > }; > > [self callFunctionOnMainThread:WTFMove(work)]; >- dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); >+ m_semaphore.wait(); > > LockHolder lock(m_mutex); > if (!m_handle) >@@ -191,17 +189,17 @@ - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectio > auto work = [self, protectedSelf, protectionSpace = retainPtr(protectionSpace)] () mutable { > if (!m_handle) { > m_boolResult = NO; >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > return; > } > m_handle->canAuthenticateAgainstProtectionSpace(ProtectionSpace(protectionSpace.get()), [self, protectedSelf = WTFMove(protectedSelf)] (bool result) mutable { > m_boolResult = result; >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > }); > }; > > [self callFunctionOnMainThread:WTFMove(work)]; >- dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); >+ m_semaphore.wait(); > > LockHolder lock(m_mutex); > if (!m_handle) >@@ -226,7 +224,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon > auto work = [self, protectedSelf, r = retainPtr(r), connection = retainPtr(connection)] () mutable { > RefPtr<ResourceHandle> protectedHandle(m_handle); > if (!m_handle || !m_handle->client()) { >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > return; > } > >@@ -245,12 +243,12 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon > ResourceHandle::getConnectionTimingData(connection.get(), resourceResponse.deprecatedNetworkLoadMetrics()); > > m_handle->didReceiveResponse(WTFMove(resourceResponse), [self, protectedSelf = WTFMove(protectedSelf)] { >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > }); > }; > > [self callFunctionOnMainThread:WTFMove(work)]; >- dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); >+ m_semaphore.wait(); > > // Make sure we get destroyed on the main thread. > [self callFunctionOnMainThread:[protectedSelf = WTFMove(protectedSelf)] { }]; >@@ -351,18 +349,18 @@ - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheRespo > auto work = [self, protectedSelf, cachedResponse = retainPtr(cachedResponse)] () mutable { > if (!m_handle || !m_handle->client()) { > m_cachedResponseResult = nullptr; >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > return; > } > > m_handle->client()->willCacheResponseAsync(m_handle, cachedResponse.get(), [self, protectedSelf = WTFMove(protectedSelf)] (NSCachedURLResponse * response) mutable { > m_cachedResponseResult = response; >- dispatch_semaphore_signal(m_semaphore); >+ m_semaphore.signal(); > }); > }; > > [self callFunctionOnMainThread:WTFMove(work)]; >- dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); >+ m_semaphore.wait(); > > LockHolder lock(m_mutex); > if (!m_handle) >diff --git a/Source/WebKit/Platform/IPC/Connection.cpp b/Source/WebKit/Platform/IPC/Connection.cpp >index 9e27540315d6e968d922b7d46bc7622991b817d3..8e6f935848244aa6d42a6e196fce829321f83917 100644 >--- a/Source/WebKit/Platform/IPC/Connection.cpp >+++ b/Source/WebKit/Platform/IPC/Connection.cpp >@@ -82,7 +82,7 @@ class Connection::SyncMessageState { > > bool wait(TimeWithDynamicClockType absoluteTime) > { >- return m_waitForSyncReplySemaphore.wait(absoluteTime); >+ return m_waitForSyncReplySemaphore.waitUntil(absoluteTime); > } > > // Returns true if this message will be handled on a client thread that is currently >diff --git a/Source/WebKit/Shared/mac/SecItemShim.cpp b/Source/WebKit/Shared/mac/SecItemShim.cpp >index c9039b2dff2295f186bd443e2f362690f3c44acf..c46b12f7d30806e227cda185297c0f5fc12900e1 100644 >--- a/Source/WebKit/Shared/mac/SecItemShim.cpp >+++ b/Source/WebKit/Shared/mac/SecItemShim.cpp >@@ -39,6 +39,7 @@ > #include <dlfcn.h> > #include <mutex> > #include <wtf/ProcessPrivilege.h> >+#include <wtf/threads/BinarySemaphore.h> > > #if USE(APPLE_INTERNAL_SDK) > #include <CFNetwork/CFURLConnectionPriv.h> >@@ -77,16 +78,16 @@ static std::optional<SecItemResponseData> sendSecItemRequest(SecItemRequestData: > > std::optional<SecItemResponseData> response; > >- auto semaphore = adoptOSObject(dispatch_semaphore_create(0)); >+ BinarySemaphore semaphore; > > sharedProcess->parentProcessConnection()->sendWithReply(Messages::SecItemShimProxy::SecItemRequest(SecItemRequestData(requestType, query, attributesToMatch)), 0, workQueue(), [&response, &semaphore](auto reply) { > if (reply) > response = WTFMove(std::get<0>(*reply)); > >- dispatch_semaphore_signal(semaphore.get()); >+ semaphore.signal(); > }); > >- dispatch_semaphore_wait(semaphore.get(), DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > > return response; > } >diff --git a/Source/WebKit/UIProcess/ResourceLoadStatisticsPersistentStorage.cpp b/Source/WebKit/UIProcess/ResourceLoadStatisticsPersistentStorage.cpp >index b67cade25dfcc9bacf579c66b5507fef0accbb7c..0c91f2026e8f183485ac360e2d25985a38adb59c 100644 >--- a/Source/WebKit/UIProcess/ResourceLoadStatisticsPersistentStorage.cpp >+++ b/Source/WebKit/UIProcess/ResourceLoadStatisticsPersistentStorage.cpp >@@ -332,7 +332,7 @@ void ResourceLoadStatisticsPersistentStorage::finishAllPendingWorkSynchronously( > writeMemoryStoreToDisk(); > semaphore.signal(); > }); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > > void ResourceLoadStatisticsPersistentStorage::ref() >diff --git a/Source/WebKit/UIProcess/WebStorage/StorageManager.cpp b/Source/WebKit/UIProcess/WebStorage/StorageManager.cpp >index 7f702e18eb3a67dbe476e693a0f420d13b4cf769..d7ae4cee5b2c697425649ab79d037b1a8463b7a3 100644 >--- a/Source/WebKit/UIProcess/WebStorage/StorageManager.cpp >+++ b/Source/WebKit/UIProcess/WebStorage/StorageManager.cpp >@@ -828,7 +828,7 @@ void StorageManager::applicationWillTerminate() > > semaphore.signal(); > }); >- semaphore.wait(WallTime::infinity()); >+ semaphore.wait(); > } > > StorageManager::StorageArea* StorageManager::findStorageArea(IPC::Connection& connection, uint64_t storageMapID) const >diff --git a/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm b/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm >index 81e1412da380eea1d203cbb36c30337d103d38d7..cef25e4809db3e805cec0deabd32e27126d65bc9 100644 >--- a/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm >+++ b/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm >@@ -46,6 +46,7 @@ > #import <WebCore/WebCoreNSURLExtras.h> > #import <wtf/SoftLinking.h> > #import <wtf/text/WTFString.h> >+#import <wtf/threads/BinarySemaphore.h> > > #if HAVE(APP_LINKS) > #import <pal/spi/cocoa/LaunchServicesSPI.h> >@@ -72,14 +73,15 @@ static bool applicationHasAppLinkEntitlements() > > static LSAppLink *appLinkForURL(NSURL *url) > { >+ BinarySemaphore semaphore; > __block LSAppLink *syncAppLink = nil; >+ __block BinarySemaphore* semaphorePtr = &semaphore; > >- dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); > [LSAppLink getAppLinkWithURL:url completionHandler:^(LSAppLink *appLink, NSError *error) { > syncAppLink = [appLink retain]; >- dispatch_semaphore_signal(semaphore); >+ semaphorePtr->signal(); > }]; >- dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); >+ semaphore.wait(); > > return [syncAppLink autorelease]; > } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 5316f6465c6a9d226a48a1b4fb53a1de7253100c..41b7a585ef491329fc033dcc7e4fabaff04726b1 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,14 @@ >+2018-05-04 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >+ https://bugs.webkit.org/show_bug.cgi?id=185339 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp: >+ (TestWebKitAPI::ToUpperConverter::stopProducing): >+ (TestWebKitAPI::ToUpperConverter::stopConsuming): >+ > 2018-05-04 Timothy Hatcher <timothy@apple.com> > > Deprecate legacy WebView and friends >diff --git a/Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp b/Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp >index 81bbc10ff0df5fd4ce00dd6b57f93f5f6e9bfc1e..f7a48db75f63e5b77cfe48cb3621e0ac73fa9942 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp >@@ -123,7 +123,7 @@ class ToUpperConverter { > return; > > m_lowerQueue->close(); >- m_produceCloseSemaphore.wait(WallTime::infinity()); >+ m_produceCloseSemaphore.wait(); > m_produceQueue = nullptr; > } > >@@ -133,7 +133,7 @@ class ToUpperConverter { > return; > > m_upperQueue->close(); >- m_consumeCloseSemaphore.wait(WallTime::infinity()); >+ m_consumeCloseSemaphore.wait(); > m_consumeQueue = nullptr; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
mark.lam
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185339
:
339625
|
339627
|
339631
| 339632