Use Box<BinarySemaphore> instead of dispatch_semaphore_t
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Nov 2018 12:50:21 +0000 (12:50 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Nov 2018 12:50:21 +0000 (12:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189691

Reviewed by Ryosuke Niwa.

Use Box<BinarySemaphore> instead, which utilizes our WTF::Lock mechanism.

* NetworkProcess/watchos/NetworkProximityManager.mm:
(WebKit::NetworkProximityManager::updateRecommendation):

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

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.mm

index bd834ff..156613a 100644 (file)
@@ -1,3 +1,15 @@
+2018-11-18  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        Use Box<BinarySemaphore> instead of dispatch_semaphore_t
+        https://bugs.webkit.org/show_bug.cgi?id=189691
+
+        Reviewed by Ryosuke Niwa.
+
+        Use Box<BinarySemaphore> instead, which utilizes our WTF::Lock mechanism.
+
+        * NetworkProcess/watchos/NetworkProximityManager.mm:
+        (WebKit::NetworkProximityManager::updateRecommendation):
+
 2018-11-17  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] Remove all usages of UIItemProvider, UIItemProviderReading, and related classes
index 33c9e2c..66facf3 100644 (file)
 #import <WirelessCoexManager/WRM_iRATInterface.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/BlockPtr.h>
+#import <wtf/Box.h>
 #import <wtf/CompletionHandler.h>
 #import <wtf/cf/TypeCastsCF.h>
+#import <wtf/threads/BinarySemaphore.h>
 
 WTF_DECLARE_CF_TYPE_TRAIT(SCNetworkInterface);
 
@@ -298,13 +300,12 @@ void NetworkProximityManager::updateRecommendation()
 
     RELEASE_LOG(ProximityNetworking, "Requesting an immediate recommendation from iRATManager.");
 
-    auto semaphore = adoptOSObject(dispatch_semaphore_create(0));
+    auto semaphore = Box<BinarySemaphore>::create();
     [m_iRATInterface getProximityLinkRecommendation:NO recommendation:[this, semaphore](NSArray<WRM_iRATProximityRecommendation *> *recommendations) {
         processRecommendations(recommendations);
-        dispatch_semaphore_signal(semaphore.get());
+        semaphore->signal();
     }];
-
-    dispatch_semaphore_wait(semaphore.get(), dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC));
+    semaphore->waitFor(1_s);
 }
 
 void NetworkProximityManager::initialize(const NetworkProcessCreationParameters& parameters)