Title: [224137] trunk/Source/WTF
Revision
224137
Author
commit-qu...@webkit.org
Date
2017-10-27 17:09:47 -0700 (Fri, 27 Oct 2017)

Log Message

[WinCairo] Add WTF files for wincairo webkit
https://bugs.webkit.org/show_bug.cgi?id=176894

Patch by Yousuke Kimoto <yousuke.kim...@sony.com> on 2017-10-27
Reviewed by Alex Christensen.

* wtf/PlatformWin.cmake:
* wtf/WorkQueue.cpp:
* wtf/WorkQueue.h:
* wtf/win/Win32Handle.h:
* wtf/win/WorkItemContext.cpp: Added.
(WTF::WorkItemContext::WorkItemContext):
(WTF::WorkItemContext::create):
(WTF::WorkItemContext::~WorkItemContext):
* wtf/win/WorkItemContext.h: Added.
(WTF::WorkItemContext::handle):
(WTF::WorkItemContext::waitHandle):
(WTF::WorkItemContext::Function<void):
(WTF::WorkItemContext::queue const):
* wtf/win/WorkQueueWin.cpp:
(WTF::WorkQueue::handleCallback):
(WTF::WorkQueue::registerHandle):
(WTF::WorkQueue::unregisterAndCloseHandle):
(WTF::WorkQueue::unregisterWaitAndDestroyItemSoon):
(WTF::WorkQueue::unregisterWaitAndDestroyItemCallback):

Modified Paths

Added Paths

Property Changed

Diff

Modified: trunk/Source/WTF/ChangeLog (224136 => 224137)


--- trunk/Source/WTF/ChangeLog	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/ChangeLog	2017-10-28 00:09:47 UTC (rev 224137)
@@ -1,3 +1,30 @@
+2017-10-27  Yousuke Kimoto  <yousuke.kim...@sony.com>
+
+        [WinCairo] Add WTF files for wincairo webkit
+        https://bugs.webkit.org/show_bug.cgi?id=176894
+
+        Reviewed by Alex Christensen.
+
+        * wtf/PlatformWin.cmake:
+        * wtf/WorkQueue.cpp:
+        * wtf/WorkQueue.h:
+        * wtf/win/Win32Handle.h:
+        * wtf/win/WorkItemContext.cpp: Added.
+        (WTF::WorkItemContext::WorkItemContext):
+        (WTF::WorkItemContext::create):
+        (WTF::WorkItemContext::~WorkItemContext):
+        * wtf/win/WorkItemContext.h: Added.
+        (WTF::WorkItemContext::handle):
+        (WTF::WorkItemContext::waitHandle):
+        (WTF::WorkItemContext::Function<void):
+        (WTF::WorkItemContext::queue const):
+        * wtf/win/WorkQueueWin.cpp:
+        (WTF::WorkQueue::handleCallback):
+        (WTF::WorkQueue::registerHandle):
+        (WTF::WorkQueue::unregisterAndCloseHandle):
+        (WTF::WorkQueue::unregisterWaitAndDestroyItemSoon):
+        (WTF::WorkQueue::unregisterWaitAndDestroyItemCallback):
+
 2017-10-27  Keith Miller  <keith_mil...@apple.com>
 
         Add unified source list files and build scripts to Xcode project navigator

Modified: trunk/Source/WTF/wtf/PlatformWin.cmake (224136 => 224137)


--- trunk/Source/WTF/wtf/PlatformWin.cmake	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/wtf/PlatformWin.cmake	2017-10-28 00:09:47 UTC (rev 224137)
@@ -11,6 +11,7 @@
     win/MemoryFootprintWin.cpp
     win/MemoryPressureHandlerWin.cpp
     win/RunLoopWin.cpp
+    win/WorkItemContext.cpp
     win/WorkQueueWin.cpp
 )
 

Modified: trunk/Source/WTF/wtf/WorkQueue.cpp (224136 => 224137)


--- trunk/Source/WTF/wtf/WorkQueue.cpp	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/wtf/WorkQueue.cpp	2017-10-28 00:09:47 UTC (rev 224137)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +39,10 @@
 #include <wtf/text/WTFString.h>
 #include <wtf/threads/BinarySemaphore.h>
 
+#if USE(WINDOWS_EVENT_LOOP)
+#include <wtf/win/WorkItemContext.h>
+#endif
+
 namespace WTF {
 
 Ref<WorkQueue> WorkQueue::create(const char* name, Type type, QOS qos)
Property changes on: trunk/Source/WTF/wtf/WorkQueue.cpp
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property

Modified: trunk/Source/WTF/wtf/WorkQueue.h (224136 => 224137)


--- trunk/Source/WTF/wtf/WorkQueue.h	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/wtf/WorkQueue.h	2017-10-28 00:09:47 UTC (rev 224137)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,6 +38,7 @@
 #endif
 
 #if USE(WINDOWS_EVENT_LOOP)
+#include <wtf/HashMap.h>
 #include <wtf/ThreadingPrimitives.h>
 #include <wtf/Vector.h>
 #endif
@@ -48,7 +50,12 @@
 
 namespace WTF {
 
+#if USE(WINDOWS_EVENT_LOOP)
+class WorkItemContext;
+#endif
+
 class WorkQueue final : public FunctionDispatcher {
+
 public:
     enum class Type {
         Serial,
@@ -74,6 +81,9 @@
     dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
 #elif USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
     RunLoop& runLoop() const { return *m_runLoop; }
+#elif USE(WINDOWS_EVENT_LOOP)
+    WTF_EXPORT_PRIVATE void registerHandle(HANDLE, Function<void()>&&);
+    WTF_EXPORT_PRIVATE void unregisterAndCloseHandle(HANDLE);
 #endif
 
 private:
@@ -83,6 +93,7 @@
     void platformInvalidate();
 
 #if USE(WINDOWS_EVENT_LOOP)
+    static void CALLBACK handleCallback(void* context, BOOLEAN timerOrWaitFired);
     static void CALLBACK timerCallback(void* context, BOOLEAN timerOrWaitFired);
     static DWORD WINAPI workThreadCallback(void* context);
 
@@ -89,6 +100,9 @@
     bool tryRegisterAsWorkThread();
     void unregisterAsWorkThread();
     void performWorkOnRegisteredWorkThread();
+
+    static void unregisterWaitAndDestroyItemSoon(Ref<WorkItemContext>&&);
+    static DWORD WINAPI unregisterWaitAndDestroyItemCallback(void* context);
 #endif
 
 #if USE(COCOA_EVENT_LOOP)
@@ -100,6 +114,9 @@
     Mutex m_functionQueueLock;
     Vector<Function<void()>> m_functionQueue;
 
+    Mutex m_itemsMapLock;
+    HashMap<HANDLE, Ref<WorkItemContext>> m_itemsMap;
+
     HANDLE m_timerQueue;
 #elif USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
     RefPtr<Thread> m_workQueueThread;

Modified: trunk/Source/WTF/wtf/win/Win32Handle.h (224136 => 224137)


--- trunk/Source/WTF/wtf/win/Win32Handle.h	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/wtf/win/Win32Handle.h	2017-10-28 00:09:47 UTC (rev 224137)
@@ -32,6 +32,9 @@
 
 class Win32Handle {
     WTF_MAKE_NONCOPYABLE(Win32Handle);
+
+    friend class WorkQueue;
+
 public:
     Win32Handle() : m_handle(INVALID_HANDLE_VALUE) { }
     explicit Win32Handle(HANDLE handle) : m_handle(handle) { }

Added: trunk/Source/WTF/wtf/win/WorkItemContext.cpp (0 => 224137)


--- trunk/Source/WTF/wtf/win/WorkItemContext.cpp	                        (rev 0)
+++ trunk/Source/WTF/wtf/win/WorkItemContext.cpp	2017-10-28 00:09:47 UTC (rev 224137)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include "WorkItemContext.h"
+
+#include <Windows.h>
+#include <wtf/Threading.h>
+#include <wtf/WorkQueue.h>
+
+namespace WTF {
+
+WorkItemContext::WorkItemContext(HANDLE handle, HANDLE waitHandle, Function<void()>&& function, WorkQueue* queue)
+    : m_handle(handle)
+    , m_waitHandle(waitHandle)
+    , m_function(WTFMove(function))
+    , m_queue(queue)
+{
+}
+
+Ref<WorkItemContext> WorkItemContext::create(HANDLE handle, HANDLE waitHandle, Function<void()>&& function, WorkQueue* queue)
+{
+    return adoptRef(*new WorkItemContext(handle, waitHandle, WTFMove(function), queue));
+}
+
+WorkItemContext::~WorkItemContext()
+{
+}
+
+} // namespace WTF
Property changes on: trunk/Source/WTF/wtf/win/WorkItemContext.cpp
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property

Added: trunk/Source/WTF/wtf/win/WorkItemContext.h (0 => 224137)


--- trunk/Source/WTF/wtf/win/WorkItemContext.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/win/WorkItemContext.h	2017-10-28 00:09:47 UTC (rev 224137)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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 <Windows.h>
+#include <functional>
+#include <wtf/FunctionDispatcher.h>
+#include <wtf/RefPtr.h>
+#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/win/Win32Handle.h>
+
+namespace WTF {
+
+class WorkQueue;
+
+class WorkItemContext : public ThreadSafeRefCounted<WorkItemContext> {
+
+public:
+    static Ref<WorkItemContext> create(HANDLE, HANDLE, Function<void()>&&, WorkQueue*);
+    virtual ~WorkItemContext();
+
+    Win32Handle& handle() { return m_handle; }
+    Win32Handle& waitHandle() { return m_waitHandle; }
+    Function<void()>& function() { return m_function; }
+    WorkQueue* queue() const { return m_queue.get(); }
+
+private:
+    WorkItemContext(HANDLE, HANDLE, Function<void()>&&, WorkQueue*);
+
+    Win32Handle m_handle;
+    Win32Handle m_waitHandle;
+    Function<void()> m_function;
+    RefPtr<WorkQueue> m_queue;
+};
+
+}

Modified: trunk/Source/WTF/wtf/win/WorkQueueWin.cpp (224136 => 224137)


--- trunk/Source/WTF/wtf/win/WorkQueueWin.cpp	2017-10-27 23:45:07 UTC (rev 224136)
+++ trunk/Source/WTF/wtf/win/WorkQueueWin.cpp	2017-10-28 00:09:47 UTC (rev 224137)
@@ -1,27 +1,28 @@
 /*
-* Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
-*
-* 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. AND ITS CONTRIBUTORS ``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 ITS 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.
-*/
+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
 
 #include "config.h"
 #include "WorkQueue.h"
@@ -28,9 +29,44 @@
 
 #include <wtf/MathExtras.h>
 #include <wtf/Threading.h>
+#include <wtf/win/WorkItemContext.h>
 
 namespace WTF {
 
+void WorkQueue::handleCallback(void* data, BOOLEAN timerOrWaitFired)
+{
+    ASSERT_ARG(data, data);
+    ASSERT_ARG(timerOrWaitFired, !timerOrWaitFired);
+
+    WorkItemContext* context = static_cast<WorkItemContext*>(data);
+    WorkQueue* queue = context->queue();
+
+    RefPtr<WorkItemContext> protector(context);
+    queue->dispatch([protector] {
+        protector->function()();
+    });
+}
+
+void WorkQueue::registerHandle(HANDLE handle, Function<void()>&& function)
+{
+    Ref<WorkItemContext> context = WorkItemContext::create(handle, nullptr, WTFMove(function), this);
+
+    if (!::RegisterWaitForSingleObject(&context->waitHandle().m_handle, handle, handleCallback, context.ptr(), INFINITE, WT_EXECUTEDEFAULT))
+        ASSERT_WITH_MESSAGE(m_timerQueue, "::RegisterWaitForSingleObject %lu", ::GetLastError());
+
+    MutexLocker lock(m_itemsMapLock);
+    ASSERT_ARG(handle, !m_itemsMap.contains(handle));
+    m_itemsMap.set(handle, WTFMove(context));
+}
+
+void WorkQueue::unregisterAndCloseHandle(HANDLE handle)
+{
+    MutexLocker locker(m_itemsMapLock);
+    ASSERT_ARG(handle, m_itemsMap.contains(handle));
+
+    unregisterWaitAndDestroyItemSoon(WTFMove(m_itemsMap.take(handle).value()));
+}
+
 DWORD WorkQueue::workThreadCallback(void* context)
 {
     ASSERT_ARG(context, context);
@@ -190,4 +226,26 @@
     context.leakRef();
 }
 
+void WorkQueue::unregisterWaitAndDestroyItemSoon(Ref<WorkItemContext>&& workItem)
+{
+    // We're going to make a blocking call to ::UnregisterWaitEx before closing the handle. (The
+    // blocking version of ::UnregisterWaitEx is much simpler than the non-blocking version.) If we
+    // do this on the current thread, we'll deadlock if we're currently in a callback function for
+    // the wait we're unregistering. So instead we do it asynchronously on some other worker thread.
+    ::QueueUserWorkItem(unregisterWaitAndDestroyItemCallback, workItem.ptr(), WT_EXECUTEDEFAULT);
+}
+
+DWORD WINAPI WorkQueue::unregisterWaitAndDestroyItemCallback(void* data)
+{
+    ASSERT_ARG(data, data);
+    WorkItemContext* context = static_cast<WorkItemContext*>(data);
+
+    // Now that we know we're not in a callback function for the wait we're unregistering, we can
+    // make a blocking call to ::UnregisterWaitEx.
+    if (!::UnregisterWaitEx(context->waitHandle().get(), INVALID_HANDLE_VALUE))
+        ASSERT_WITH_MESSAGE(false, "::UnregisterWaitEx failed with '%s'", ::GetLastError());
+
+    return 0;
+}
+
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to