Changeset 162276 in webkit


Ignore:
Timestamp:
Jan 18, 2014 3:00:21 PM (10 years ago)
Author:
andersca@apple.com
Message:

Replace a couple of uses of WTF::Function with std::function
https://bugs.webkit.org/show_bug.cgi?id=127218

Reviewed by Andreas Kling.

Source/WebCore:

  • WebCore.exp.in:
  • page/scrolling/ScrollingThread.cpp:

(WebCore::ScrollingThread::dispatch):
(WebCore::ScrollingThread::dispatchBarrier):
(WebCore::ScrollingThread::shared):
(WebCore::ScrollingThread::createThreadIfNeeded):
(WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):

  • page/scrolling/ScrollingThread.h:
  • page/scrolling/mac/ScrollingThreadMac.mm:

(WebCore::ScrollingThread::initializeRunLoop):

Source/WebKit2:

  • Platform/IPC/mac/ConnectionMac.cpp:

(IPC::createDataAvailableSource):

  • Platform/WorkQueue.h:
  • Platform/mac/WorkQueueMac.cpp:

(WorkQueue::dispatch):
(WorkQueue::dispatchAfter):

  • Shared/ChildProcess.cpp:

(WebKit::didCloseOnConnectionWorkQueue):

  • UIProcess/Storage/LocalStorageDatabase.cpp:

(WebKit::LocalStorageDatabase::scheduleDatabaseUpdate):

  • WebProcess/WebPage/DrawingArea.cpp:

(WebKit::DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):

  • WebProcess/WebPage/DrawingArea.h:
  • WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
  • WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:

(WebKit::TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r162275 r162276  
     12014-01-18  Anders Carlsson  <andersca@apple.com>
     2
     3        Replace a couple of uses of WTF::Function with std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=127218
     5
     6        Reviewed by Andreas Kling.
     7
     8        * WebCore.exp.in:
     9        * page/scrolling/ScrollingThread.cpp:
     10        (WebCore::ScrollingThread::dispatch):
     11        (WebCore::ScrollingThread::dispatchBarrier):
     12        (WebCore::ScrollingThread::shared):
     13        (WebCore::ScrollingThread::createThreadIfNeeded):
     14        (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
     15        * page/scrolling/ScrollingThread.h:
     16        * page/scrolling/mac/ScrollingThreadMac.mm:
     17        (WebCore::ScrollingThread::initializeRunLoop):
     18
    1192014-01-18  Anders Carlsson  <andersca@apple.com>
    220
  • trunk/Source/WebCore/WebCore.exp.in

    r162264 r162276  
    29792979__ZN7WebCore13ScrollingTreeD1Ev
    29802980__ZN7WebCore13ScrollingTreeD2Ev
    2981 __ZN7WebCore15ScrollingThread15dispatchBarrierERKN3WTF8FunctionIFvvEEE
    2982 __ZN7WebCore15ScrollingThread8dispatchERKN3WTF8FunctionIFvvEEE
     2981__ZN7WebCore15ScrollingThread15dispatchBarrierENSt3__18functionIFvvEEE
     2982__ZN7WebCore15ScrollingThread8dispatchENSt3__18functionIFvvEEE
    29832983__ZN7WebCore18ScrollingStateNode8setLayerERKNS_19LayerRepresentationE
    29842984__ZN7WebCore18ScrollingStateTree10attachNodeENS_17ScrollingNodeTypeEyy
  • trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp

    r160944 r162276  
    3030
    3131#include <wtf/MainThread.h>
     32#include <wtf/NeverDestroyed.h>
    3233
    3334namespace WebCore {
     
    4647}
    4748
    48 void ScrollingThread::dispatch(const Function<void()>& function)
     49void ScrollingThread::dispatch(std::function<void ()> function)
    4950{
    5051    shared().createThreadIfNeeded();
    5152
    5253    {
    53         MutexLocker locker(shared().m_functionsMutex);
     54        std::lock_guard<std::mutex> lock(shared().m_functionsMutex);
    5455        shared().m_functions.append(function);
    5556    }
     
    5859}
    5960
    60 static void callFunctionOnMainThread(const Function<void()>* function)
     61void ScrollingThread::dispatchBarrier(std::function<void ()> function)
    6162{
    62     callOnMainThread(*function);
    63     delete function;
    64 }
    65 
    66 void ScrollingThread::dispatchBarrier(const Function<void()>& function)
    67 {
    68     dispatch(bind(callFunctionOnMainThread, new Function<void()>(function)));
     63    dispatch([function]{
     64        callOnMainThread(std::move(function));
     65    });
    6966}
    7067
    7168ScrollingThread& ScrollingThread::shared()
    7269{
    73     DEFINE_STATIC_LOCAL(ScrollingThread, scrollingThread, ());
     70    static NeverDestroyed<ScrollingThread> scrollingThread;
     71
    7472    return scrollingThread;
    7573}
     
    8280    // Wait for the thread to initialize the run loop.
    8381    {
    84         MutexLocker locker(m_initializeRunLoopConditionMutex);
     82        std::unique_lock<std::mutex> lock(m_initializeRunLoopMutex);
    8583
    8684        m_threadIdentifier = createThread(threadCallback, this, "WebCore: Scrolling");
    8785       
    8886#if PLATFORM(MAC)
    89         while (!m_threadRunLoop)
    90             m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex);
     87        m_initializeRunLoopConditionVariable.wait(lock, [this]{ return m_threadRunLoop; });
    9188#endif
    9289    }
     
    107104    ASSERT(isCurrentThread());
    108105
    109     Vector<Function<void()>> functions;
     106    Vector<std::function<void ()>> functions;
    110107   
    111108    {
    112         MutexLocker locker(m_functionsMutex);
    113         m_functions.swap(functions);
     109        std::lock_guard<std::mutex> lock(m_functionsMutex);
     110        functions = std::move(m_functions);
    114111    }
    115    
    116     for (size_t i = 0; i < functions.size(); ++i)
    117         functions[i]();
     112
     113    for (auto& function : functions)
     114        function();
    118115}
    119116
  • trunk/Source/WebCore/page/scrolling/ScrollingThread.h

    r160944 r162276  
    2929#if ENABLE(ASYNC_SCROLLING)
    3030
    31 #include <wtf/Functional.h>
     31#include <condition_variable>
     32#include <functional>
     33#include <wtf/Forward.h>
    3234#include <wtf/Noncopyable.h>
    3335#include <wtf/Threading.h>
     
    4547public:
    4648    static bool isCurrentThread();
    47     static void dispatch(const Function<void()>&);
     49    static void dispatch(std::function<void ()>);
    4850
    4951    // Will dispatch the given function on the main thread once all pending functions
    5052    // on the scrolling thread have finished executing. Used for synchronization purposes.
    51     static void dispatchBarrier(const Function<void()>&);
     53    static void dispatchBarrier(std::function<void ()>);
    5254
    5355private:
     56    friend NeverDestroyed<ScrollingThread>;
     57
    5458    ScrollingThread();
    5559
     
    7175    ThreadIdentifier m_threadIdentifier;
    7276
    73     ThreadCondition m_initializeRunLoopCondition;
    74     Mutex m_initializeRunLoopConditionMutex;
     77    std::condition_variable m_initializeRunLoopConditionVariable;
     78    std::mutex m_initializeRunLoopMutex;
    7579
    76     Mutex m_functionsMutex;
    77     Vector<Function<void()>> m_functions;
     80    std::mutex m_functionsMutex;
     81    Vector<std::function<void ()>> m_functions;
    7882
    7983#if PLATFORM(MAC)
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm

    r160944 r162276  
    3535    // Initialize the run loop.
    3636    {
    37         MutexLocker locker(m_initializeRunLoopConditionMutex);
     37        std::lock_guard<std::mutex> lock(m_initializeRunLoopMutex);
    3838
    3939        m_threadRunLoop = CFRunLoopGetCurrent();
     
    4343        CFRunLoopAddSource(CFRunLoopGetCurrent(), m_threadRunLoopSource.get(), kCFRunLoopDefaultMode);
    4444
    45         m_initializeRunLoopCondition.broadcast();
     45        m_initializeRunLoopConditionVariable.notify_all();
    4646    }
    4747
  • trunk/Source/WebKit2/ChangeLog

    r162271 r162276  
     12014-01-18  Anders Carlsson  <andersca@apple.com>
     2
     3        Replace a couple of uses of WTF::Function with std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=127218
     5
     6        Reviewed by Andreas Kling.
     7
     8        * Platform/IPC/mac/ConnectionMac.cpp:
     9        (IPC::createDataAvailableSource):
     10        * Platform/WorkQueue.h:
     11        * Platform/mac/WorkQueueMac.cpp:
     12        (WorkQueue::dispatch):
     13        (WorkQueue::dispatchAfter):
     14        * Shared/ChildProcess.cpp:
     15        (WebKit::didCloseOnConnectionWorkQueue):
     16        * UIProcess/Storage/LocalStorageDatabase.cpp:
     17        (WebKit::LocalStorageDatabase::scheduleDatabaseUpdate):
     18        * WebProcess/WebPage/DrawingArea.cpp:
     19        (WebKit::DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):
     20        * WebProcess/WebPage/DrawingArea.h:
     21        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
     22        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
     23        (WebKit::TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):
     24
    1252014-01-18  Martin Hock  <mhock@apple.com>
    226
  • trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp

    r161148 r162276  
    102102}
    103103
    104 static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue* workQueue, const Function<void()>& function)
     104static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue* workQueue, std::function<void ()> function)
    105105{
    106106    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, receivePort, 0, workQueue->dispatchQueue());
    107     dispatch_source_set_event_handler(source, function);
     107    dispatch_source_set_event_handler(source, ^{
     108        function();
     109    });
     110
    108111    dispatch_source_set_cancel_handler(source, ^{
    109112        mach_port_mod_refs(mach_task_self(), receivePort, MACH_PORT_RIGHT_RECEIVE, -1);
  • trunk/Source/WebKit2/Platform/WorkQueue.h

    r160162 r162276  
    3232#endif
    3333
     34#include <chrono>
     35#include <functional>
    3436#include <wtf/Forward.h>
    3537#include <wtf/Functional.h>
     
    5658    ~WorkQueue();
    5759
    58     // Will dispatch the given function to run as soon as possible.
    59     void dispatch(const Function<void()>&);
    60 
    61     // Will dispatch the given function after the given delay (in seconds).
    62     void dispatchAfterDelay(const Function<void()>&, double delay);
     60    void dispatch(std::function<void ()>);
     61    void dispatchAfter(std::chrono::nanoseconds, std::function<void ()>);
    6362
    6463#if OS(DARWIN)
  • trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp

    r141497 r162276  
    2727#include "WorkQueue.h"
    2828
    29 void WorkQueue::dispatch(const Function<void()>& function)
     29void WorkQueue::dispatch(std::function<void ()> function)
    3030{
    31     Function<void()> functionCopy = function;
    32 
    3331    ref();
    3432    dispatch_async(m_dispatchQueue, ^{
    35         functionCopy();
     33        function();
    3634        deref();
    3735    });
    3836}
    3937
    40 void WorkQueue::dispatchAfterDelay(const Function<void()>& function, double delay)
     38void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void ()> function)
    4139{
    42     dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
    43 
    44     Function<void()> functionCopy = function;
    45 
    4640    ref();
    47     dispatch_after(delayTime, m_dispatchQueue, ^{
    48         functionCopy();
     41    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{
     42        function();
    4943        deref();
    5044    });
  • trunk/Source/WebKit2/Shared/ChildProcess.cpp

    r161271 r162276  
    4545}
    4646
    47 NO_RETURN static void watchdogCallback()
    48 {
    49     // We use _exit here since the watchdog callback is called from another thread and we don't want
    50     // global destructors or atexit handlers to be called from this thread while the main thread is busy
    51     // doing its thing.
    52     _exit(EXIT_FAILURE);
    53 }
    54 
    5547static void didCloseOnConnectionWorkQueue(IPC::Connection*)
    5648{
    5749    // If the connection has been closed and we haven't responded in the main thread for 10 seconds
    5850    // the process will exit forcibly.
    59     const double watchdogDelay = 10;
     51    auto watchdogDelay = std::chrono::seconds(10);
    6052
    61     WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfterDelay(bind(static_cast<void(*)()>(watchdogCallback)), watchdogDelay);
     53    WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfter(watchdogDelay, []{
     54        // We use _exit here since the watchdog callback is called from another thread and we don't want
     55        // global destructors or atexit handlers to be called from this thread while the main thread is busy
     56        // doing its thing.
     57        _exit(EXIT_FAILURE);
     58    });
    6259}
    6360
  • trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp

    r150304 r162276  
    4040using namespace WebCore;
    4141
    42 static const double databaseUpdateIntervalInSeconds = 1.0;
     42static const auto databaseUpdateInterval = std::chrono::seconds(1);
    4343
    4444static const int maximumItemsToUpdate = 100;
     
    242242
    243243    m_didScheduleDatabaseUpdate = true;
    244     m_queue->dispatchAfterDelay(bind(&LocalStorageDatabase::updateDatabase, this), databaseUpdateIntervalInSeconds);
     244    m_queue->dispatchAfter(databaseUpdateInterval, bind(&LocalStorageDatabase::updateDatabase, this));
    245245}
    246246
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.cpp

    r160031 r162276  
    7878}
    7979
    80 void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>& function)
     80void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function)
    8181{
    8282    // Scroll position updates are synchronous by default so we can just call the function right away here.
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h

    r161548 r162276  
    3232#include <WebCore/IntRect.h>
    3333#include <WebCore/ViewState.h>
     34#include <functional>
    3435#include <wtf/Forward.h>
    3536#include <wtf/Noncopyable.h>
     
    109110#endif
    110111
    111     virtual void dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>&);
     112    virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>);
    112113
    113114    virtual void viewStateDidChange(WebCore::ViewState::Flags) { }
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h

    r162139 r162276  
    8585    virtual void didChangeScrollOffsetForAnyFrame() override;
    8686
    87     virtual void dispatchAfterEnsuringUpdatedScrollPosition(const Function<void()>&) override;
     87    virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>) override;
    8888
    8989    virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override;
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm

    r161530 r162276  
    301301}
    302302
    303 void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>& functionRef)
    304 {
    305     Function<void ()> function = functionRef;
    306 
     303void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function)
     304{
    307305#if ENABLE(ASYNC_SCROLLING)
    308306    if (!m_webPage->corePage()->scrollingCoordinator()) {
Note: See TracChangeset for help on using the changeset viewer.