Changeset 224137 in webkit


Ignore:
Timestamp:
Oct 27, 2017 5:09:47 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Yousuke Kimoto <yousuke.kimoto@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):

Location:
trunk/Source/WTF
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r224136 r224137  
     12017-10-27  Yousuke Kimoto  <yousuke.kimoto@sony.com>
     2
     3        [WinCairo] Add WTF files for wincairo webkit
     4        https://bugs.webkit.org/show_bug.cgi?id=176894
     5
     6        Reviewed by Alex Christensen.
     7
     8        * wtf/PlatformWin.cmake:
     9        * wtf/WorkQueue.cpp:
     10        * wtf/WorkQueue.h:
     11        * wtf/win/Win32Handle.h:
     12        * wtf/win/WorkItemContext.cpp: Added.
     13        (WTF::WorkItemContext::WorkItemContext):
     14        (WTF::WorkItemContext::create):
     15        (WTF::WorkItemContext::~WorkItemContext):
     16        * wtf/win/WorkItemContext.h: Added.
     17        (WTF::WorkItemContext::handle):
     18        (WTF::WorkItemContext::waitHandle):
     19        (WTF::WorkItemContext::Function<void):
     20        (WTF::WorkItemContext::queue const):
     21        * wtf/win/WorkQueueWin.cpp:
     22        (WTF::WorkQueue::handleCallback):
     23        (WTF::WorkQueue::registerHandle):
     24        (WTF::WorkQueue::unregisterAndCloseHandle):
     25        (WTF::WorkQueue::unregisterWaitAndDestroyItemSoon):
     26        (WTF::WorkQueue::unregisterWaitAndDestroyItemCallback):
     27
    1282017-10-27  Keith Miller  <keith_miller@apple.com>
    229
  • trunk/Source/WTF/wtf/PlatformWin.cmake

    r221768 r224137  
    1212    win/MemoryPressureHandlerWin.cpp
    1313    win/RunLoopWin.cpp
     14    win/WorkItemContext.cpp
    1415    win/WorkQueueWin.cpp
    1516)
  • trunk/Source/WTF/wtf/WorkQueue.cpp

    • Property svn:executable set to *
    r217998 r224137  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2017 Sony Interactive Entertainment Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3839#include <wtf/text/WTFString.h>
    3940#include <wtf/threads/BinarySemaphore.h>
     41
     42#if USE(WINDOWS_EVENT_LOOP)
     43#include <wtf/win/WorkItemContext.h>
     44#endif
    4045
    4146namespace WTF {
  • trunk/Source/WTF/wtf/WorkQueue.h

    r218594 r224137  
    22 * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
    33 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
     4 * Copyright (C) 2017 Sony Interactive Entertainment Inc.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3839
    3940#if USE(WINDOWS_EVENT_LOOP)
     41#include <wtf/HashMap.h>
    4042#include <wtf/ThreadingPrimitives.h>
    4143#include <wtf/Vector.h>
     
    4951namespace WTF {
    5052
     53#if USE(WINDOWS_EVENT_LOOP)
     54class WorkItemContext;
     55#endif
     56
    5157class WorkQueue final : public FunctionDispatcher {
     58
    5259public:
    5360    enum class Type {
     
    7582#elif USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
    7683    RunLoop& runLoop() const { return *m_runLoop; }
     84#elif USE(WINDOWS_EVENT_LOOP)
     85    WTF_EXPORT_PRIVATE void registerHandle(HANDLE, Function<void()>&&);
     86    WTF_EXPORT_PRIVATE void unregisterAndCloseHandle(HANDLE);
    7787#endif
    7888
     
    8494
    8595#if USE(WINDOWS_EVENT_LOOP)
     96    static void CALLBACK handleCallback(void* context, BOOLEAN timerOrWaitFired);
    8697    static void CALLBACK timerCallback(void* context, BOOLEAN timerOrWaitFired);
    8798    static DWORD WINAPI workThreadCallback(void* context);
     
    90101    void unregisterAsWorkThread();
    91102    void performWorkOnRegisteredWorkThread();
     103
     104    static void unregisterWaitAndDestroyItemSoon(Ref<WorkItemContext>&&);
     105    static DWORD WINAPI unregisterWaitAndDestroyItemCallback(void* context);
    92106#endif
    93107
     
    100114    Mutex m_functionQueueLock;
    101115    Vector<Function<void()>> m_functionQueue;
     116
     117    Mutex m_itemsMapLock;
     118    HashMap<HANDLE, Ref<WorkItemContext>> m_itemsMap;
    102119
    103120    HANDLE m_timerQueue;
  • trunk/Source/WTF/wtf/win/Win32Handle.h

    r213214 r224137  
    3333class Win32Handle {
    3434    WTF_MAKE_NONCOPYABLE(Win32Handle);
     35
     36    friend class WorkQueue;
     37
    3538public:
    3639    Win32Handle() : m_handle(INVALID_HANDLE_VALUE) { }
  • trunk/Source/WTF/wtf/win/WorkQueueWin.cpp

    r221425 r224137  
    11/*
    2 * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
    3 *
    4 * Redistribution and use in source and binary forms, with or without
    5 * modification, are permitted provided that the following conditions
    6 * are met:
    7 * 1. Redistributions of source code must retain the above copyright
    8 *    notice, this list of conditions and the following disclaimer.
    9 * 2. Redistributions in binary form must reproduce the above copyright
    10 *    notice, this list of conditions and the following disclaimer in the
    11 *    documentation and/or other materials provided with the distribution.
    12 *
    13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
    14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
    17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    23 * THE POSSIBILITY OF SUCH DAMAGE.
    24 */
     2 * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
     3 * Copyright (C) 2017 Sony Interactive Entertainment Inc.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 *
     14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     24 * THE POSSIBILITY OF SUCH DAMAGE.
     25 */
    2526
    2627#include "config.h"
     
    2930#include <wtf/MathExtras.h>
    3031#include <wtf/Threading.h>
     32#include <wtf/win/WorkItemContext.h>
    3133
    3234namespace WTF {
     35
     36void WorkQueue::handleCallback(void* data, BOOLEAN timerOrWaitFired)
     37{
     38    ASSERT_ARG(data, data);
     39    ASSERT_ARG(timerOrWaitFired, !timerOrWaitFired);
     40
     41    WorkItemContext* context = static_cast<WorkItemContext*>(data);
     42    WorkQueue* queue = context->queue();
     43
     44    RefPtr<WorkItemContext> protector(context);
     45    queue->dispatch([protector] {
     46        protector->function()();
     47    });
     48}
     49
     50void WorkQueue::registerHandle(HANDLE handle, Function<void()>&& function)
     51{
     52    Ref<WorkItemContext> context = WorkItemContext::create(handle, nullptr, WTFMove(function), this);
     53
     54    if (!::RegisterWaitForSingleObject(&context->waitHandle().m_handle, handle, handleCallback, context.ptr(), INFINITE, WT_EXECUTEDEFAULT))
     55        ASSERT_WITH_MESSAGE(m_timerQueue, "::RegisterWaitForSingleObject %lu", ::GetLastError());
     56
     57    MutexLocker lock(m_itemsMapLock);
     58    ASSERT_ARG(handle, !m_itemsMap.contains(handle));
     59    m_itemsMap.set(handle, WTFMove(context));
     60}
     61
     62void WorkQueue::unregisterAndCloseHandle(HANDLE handle)
     63{
     64    MutexLocker locker(m_itemsMapLock);
     65    ASSERT_ARG(handle, m_itemsMap.contains(handle));
     66
     67    unregisterWaitAndDestroyItemSoon(WTFMove(m_itemsMap.take(handle).value()));
     68}
    3369
    3470DWORD WorkQueue::workThreadCallback(void* context)
     
    191227}
    192228
     229void WorkQueue::unregisterWaitAndDestroyItemSoon(Ref<WorkItemContext>&& workItem)
     230{
     231    // We're going to make a blocking call to ::UnregisterWaitEx before closing the handle. (The
     232    // blocking version of ::UnregisterWaitEx is much simpler than the non-blocking version.) If we
     233    // do this on the current thread, we'll deadlock if we're currently in a callback function for
     234    // the wait we're unregistering. So instead we do it asynchronously on some other worker thread.
     235    ::QueueUserWorkItem(unregisterWaitAndDestroyItemCallback, workItem.ptr(), WT_EXECUTEDEFAULT);
     236}
     237
     238DWORD WINAPI WorkQueue::unregisterWaitAndDestroyItemCallback(void* data)
     239{
     240    ASSERT_ARG(data, data);
     241    WorkItemContext* context = static_cast<WorkItemContext*>(data);
     242
     243    // Now that we know we're not in a callback function for the wait we're unregistering, we can
     244    // make a blocking call to ::UnregisterWaitEx.
     245    if (!::UnregisterWaitEx(context->waitHandle().get(), INVALID_HANDLE_VALUE))
     246        ASSERT_WITH_MESSAGE(false, "::UnregisterWaitEx failed with '%s'", ::GetLastError());
     247
     248    return 0;
     249}
     250
    193251} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.