Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 00:46:47 +0000 (00:46 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 00:46:47 +0000 (00:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180060

Reviewed by Alex Christensen.

Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h so that it can be reused.

Source/WebCore:

* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::callOnMainThreadAndWait): Deleted.

Source/WTF:

* wtf/MainThread.cpp:
(WTF::callOnMainThreadAndWait):
* wtf/MainThread.h:

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

Source/WTF/ChangeLog
Source/WTF/wtf/MainThread.cpp
Source/WTF/wtf/MainThread.h
Source/WebCore/ChangeLog
Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp

index b7bd6be..bb0e406 100644 (file)
@@ -1,3 +1,16 @@
+2017-11-27  Chris Dumez  <cdumez@apple.com>
+
+        Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h
+        https://bugs.webkit.org/show_bug.cgi?id=180060
+
+        Reviewed by Alex Christensen.
+
+        Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h so that it can be reused.
+
+        * wtf/MainThread.cpp:
+        (WTF::callOnMainThreadAndWait):
+        * wtf/MainThread.h:
+
 2017-11-27  Simon Fraser  <simon.fraser@apple.com>
 
         Use TextStream's indent tracking, rather than passing indent to all the externalRepresentation() functions
index 0771c93..2c41627 100644 (file)
@@ -35,6 +35,7 @@
 #include "StdLibExtras.h"
 #include "Threading.h"
 #include <mutex>
+#include <wtf/Condition.h>
 #include <wtf/Lock.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/ThreadSpecific.h>
@@ -211,4 +212,30 @@ std::optional<GCThreadType> mayBeGCThread()
     return **isGCThread;
 }
 
+void callOnMainThreadAndWait(WTF::Function<void()>&& function)
+{
+    if (isMainThread()) {
+        function();
+        return;
+    }
+
+    Lock mutex;
+    Condition conditionVariable;
+
+    bool isFinished = false;
+
+    callOnMainThread([&, function = WTFMove(function)] {
+        function();
+
+        std::lock_guard<Lock> lock(mutex);
+        isFinished = true;
+        conditionVariable.notifyOne();
+    });
+
+    std::unique_lock<Lock> lock(mutex);
+    conditionVariable.wait(lock, [&] {
+        return isFinished;
+    });
+}
+
 } // namespace WTF
index 15b3784..c95f92f 100644 (file)
@@ -44,6 +44,7 @@ class PrintStream;
 WTF_EXPORT_PRIVATE void initializeMainThread();
 
 WTF_EXPORT_PRIVATE void callOnMainThread(Function<void()>&&);
+WTF_EXPORT_PRIVATE void callOnMainThreadAndWait(Function<void()>&&);
 
 #if PLATFORM(COCOA)
 WTF_EXPORT_PRIVATE void callOnWebThreadOrDispatchAsyncOnMainThread(void (^block)());
@@ -99,6 +100,7 @@ void initializeMainThreadToProcessMainThreadPlatform();
 
 using WTF::GCThreadType;
 using WTF::callOnMainThread;
+using WTF::callOnMainThreadAndWait;
 using WTF::canAccessThreadLocalDataForThread;
 using WTF::isMainThread;
 using WTF::isMainThreadOrGCThread;
index 0e6dd72..1c88e74 100644 (file)
@@ -1,3 +1,15 @@
+2017-11-27  Chris Dumez  <cdumez@apple.com>
+
+        Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h
+        https://bugs.webkit.org/show_bug.cgi?id=180060
+
+        Reviewed by Alex Christensen.
+
+        Move callOnMainThreadAndWait() from SocketStreamHandleImplCFNet.cpp to MainThread.h so that it can be reused.
+
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::callOnMainThreadAndWait): Deleted.
+
 2017-11-27  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r225201.
index 957ea6c..0486404 100644 (file)
@@ -151,32 +151,6 @@ CFStringRef SocketStreamHandleImpl::copyPACExecutionDescription(void*)
     return CFSTR("WebSocket proxy PAC file execution");
 }
 
-static void callOnMainThreadAndWait(WTF::Function<void()>&& function)
-{
-    if (isMainThread()) {
-        function();
-        return;
-    }
-
-    Lock mutex;
-    Condition conditionVariable;
-
-    bool isFinished = false;
-
-    callOnMainThread([&, function = WTFMove(function)] {
-        function();
-
-        std::lock_guard<Lock> lock(mutex);
-        isFinished = true;
-        conditionVariable.notifyOne();
-    });
-
-    std::unique_lock<Lock> lock(mutex);
-    conditionVariable.wait(lock, [&] {
-        return isFinished;
-    });
-}
-
 struct MainThreadPACCallbackInfo {
     MainThreadPACCallbackInfo(SocketStreamHandle* handle, CFArrayRef proxyList)
         : handle(handle), proxyList(proxyList)