[WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Sep 2018 05:47:33 +0000 (05:47 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Sep 2018 05:47:33 +0000 (05:47 +0000)
commit9eeb04ec1142bcc93256af0661b8bd81a6405aa0
tree4c121f065dcb0d24beaafac22e7038121d874e21
parent3926b1181dea0fd6c8be9ff5ca46608e8083e2f3
[WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t
https://bugs.webkit.org/show_bug.cgi?id=185339

Patch by Yusuke Suzuki <utatane.tea@gmail.com> on 2018-09-17
Reviewed by Mark Lam.

Source/WebCore:

* 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.

Source/WebKit:

* 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.

Source/WTF:

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()).

Tools:

* TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp:
(TestWebKitAPI::ToUpperConverter::stopProducing):
(TestWebKitAPI::ToUpperConverter::stopConsuming):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236101 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/Semaphore.h [new file with mode: 0644]
Source/WTF/wtf/generic/WorkQueueGeneric.cpp
Source/WTF/wtf/threads/BinarySemaphore.cpp
Source/WTF/wtf/threads/BinarySemaphore.h
Source/WebCore/ChangeLog
Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h
Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm
Source/WebCore/platform/glib/FileMonitorGLib.cpp
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h
Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm
Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp
Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp
Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h
Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/Connection.cpp
Source/WebKit/Shared/mac/SecItemShim.cpp
Source/WebKit/UIProcess/WebStorage/StorageManager.cpp
Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp