Changeset 102866 in webkit


Ignore:
Timestamp:
Dec 14, 2011 6:10:51 PM (12 years ago)
Author:
andersca@apple.com
Message:

Add WorkQueue::dispatch and RunLoop::dispatch which both take WTF::Function objects
https://bugs.webkit.org/show_bug.cgi?id=74574

Reviewed by Sam Weinig.

  • Platform/CoreIPC/Connection.cpp:

(CoreIPC::Connection::SyncMessageState::processIncomingMessage):
(CoreIPC::Connection::addQueueClient):
(CoreIPC::Connection::removeQueueClient):
(CoreIPC::Connection::invalidate):
(CoreIPC::Connection::sendMessage):
(CoreIPC::Connection::postConnectionDidCloseOnConnectionWorkQueue):
(CoreIPC::Connection::connectionDidClose):
(CoreIPC::Connection::enqueueIncomingMessage):
Switch over to dispatch.

  • Platform/RunLoop.cpp:

(RunLoop::dispatch):
Create a FunctionWorkItem and call scheduleWork.

  • Platform/RunLoop.h:

Add dispatch.

  • Platform/WorkItem.h:

(FunctionWorkItem::FunctionWorkItem):
(FunctionWorkItem::execute):
(WorkItem::create):
Add a helper work item that wraps a WTF::Function.

  • Platform/WorkQueue.cpp:

(WorkQueue::dispatch):
Create a FunctionWorkItem and call scheduleWork.

  • Platform/WorkQueue.h:

Add dispatch.

  • UIProcess/Launcher/ProcessLauncher.cpp:

(WebKit::ProcessLauncher::ProcessLauncher):
Switch over to dispatch.

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r102849 r102866  
     12011-12-14  Anders Carlsson  <andersca@apple.com>
     2
     3        Add WorkQueue::dispatch and RunLoop::dispatch which both take WTF::Function objects
     4        https://bugs.webkit.org/show_bug.cgi?id=74574
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Platform/CoreIPC/Connection.cpp:
     9        (CoreIPC::Connection::SyncMessageState::processIncomingMessage):
     10        (CoreIPC::Connection::addQueueClient):
     11        (CoreIPC::Connection::removeQueueClient):
     12        (CoreIPC::Connection::invalidate):
     13        (CoreIPC::Connection::sendMessage):
     14        (CoreIPC::Connection::postConnectionDidCloseOnConnectionWorkQueue):
     15        (CoreIPC::Connection::connectionDidClose):
     16        (CoreIPC::Connection::enqueueIncomingMessage):
     17        Switch over to dispatch.
     18
     19        * Platform/RunLoop.cpp:
     20        (RunLoop::dispatch):
     21        Create a FunctionWorkItem and call scheduleWork.
     22
     23        * Platform/RunLoop.h:
     24        Add dispatch.
     25
     26        * Platform/WorkItem.h:
     27        (FunctionWorkItem::FunctionWorkItem):
     28        (FunctionWorkItem::execute):
     29        (WorkItem::create):
     30        Add a helper work item that wraps a WTF::Function.
     31
     32        * Platform/WorkQueue.cpp:
     33        (WorkQueue::dispatch):
     34        Create a FunctionWorkItem and call scheduleWork.
     35
     36        * Platform/WorkQueue.h:
     37        Add dispatch.
     38
     39        * UIProcess/Launcher/ProcessLauncher.cpp:
     40        (WebKit::ProcessLauncher::ProcessLauncher):
     41        Switch over to dispatch.
     42
    1432011-12-14  Hajime Morrita  <morrita@chromium.org>
    244
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp

    r102615 r102866  
    142142       
    143143        if (!m_didScheduleDispatchMessagesWork) {
    144             m_runLoop->scheduleWork(WorkItem::create(this, &SyncMessageState::dispatchMessageAndResetDidScheduleDispatchMessagesWork));
     144            m_runLoop->dispatch(bind(&SyncMessageState::dispatchMessageAndResetDidScheduleDispatchMessagesWork, this));
    145145            m_didScheduleDispatchMessagesWork = true;
    146146        }
     
    237237void Connection::addQueueClient(QueueClient* queueClient)
    238238{
    239     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::addQueueClientOnWorkQueue, queueClient));
     239    m_connectionQueue.dispatch(bind(&Connection::addQueueClientOnWorkQueue, this, queueClient));
    240240}
    241241
    242242void Connection::removeQueueClient(QueueClient* queueClient)
    243243{
    244     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::removeQueueClientOnWorkQueue, queueClient));
     244    m_connectionQueue.dispatch(bind(&Connection::removeQueueClientOnWorkQueue, this, queueClient));
    245245}
    246246
     
    275275    m_client = 0;
    276276
    277     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::platformInvalidate));
     277    m_connectionQueue.dispatch(bind(&Connection::platformInvalidate, this));
    278278}
    279279
     
    318318   
    319319    // FIXME: We should add a boolean flag so we don't call this when work has already been scheduled.
    320     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::sendOutgoingMessages));
     320    m_connectionQueue.dispatch(bind(&Connection::sendOutgoingMessages, this));
    321321    return true;
    322322}
     
    566566void Connection::postConnectionDidCloseOnConnectionWorkQueue()
    567567{
    568     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::connectionDidClose));
     568    m_connectionQueue.dispatch(bind(&Connection::connectionDidClose, this));
    569569}
    570570
     
    587587        m_didCloseOnConnectionWorkQueueCallback(m_connectionQueue, this);
    588588
    589     m_clientRunLoop->scheduleWork(WorkItem::create(this, &Connection::dispatchConnectionDidClose));
     589    m_clientRunLoop->dispatch(bind(&Connection::dispatchConnectionDidClose, this));
    590590}
    591591
     
    667667    m_incomingMessages.append(incomingMessage);
    668668
    669     m_clientRunLoop->scheduleWork(WorkItem::create(this, &Connection::dispatchMessages));
     669    m_clientRunLoop->dispatch(bind(&Connection::dispatchMessages, this));
    670670}
    671671
  • trunk/Source/WebKit2/Platform/RunLoop.cpp

    r95901 r102866  
    6565}
    6666
     67void RunLoop::dispatch(const Function<void()>& function)
     68{
     69    scheduleWork(WorkItem::create(function));
     70}
     71
    6772void RunLoop::scheduleWork(PassOwnPtr<WorkItem> item)
    6873{
  • trunk/Source/WebKit2/Platform/RunLoop.h

    r95901 r102866  
    4848}
    4949
     50namespace WTF {
     51    template<typename> class Function;
     52}
     53using WTF::Function;
     54
    5055class RunLoop {
    5156public:
     
    5661    static RunLoop* main();
    5762
     63    // FIXME: Get rid of this overload and use WTF::Function everywhere.
    5864    void scheduleWork(PassOwnPtr<WorkItem>);
     65
     66    void dispatch(const Function<void()>&);
    5967
    6068#if PLATFORM(WIN)
  • trunk/Source/WebKit2/Platform/WorkItem.h

    r95901 r102866  
    2727#define WorkItem_h
    2828
     29#include <wtf/Functional.h>
    2930#include <wtf/PassOwnPtr.h>
    3031
     
    4546    static PassOwnPtr<WorkItem> createDeref(C*);
    4647
     48    static PassOwnPtr<WorkItem> create(const Function<void()>&);
     49
    4750    virtual ~WorkItem() { }
    4851    virtual void execute() = 0;
     
    212215}
    213216
     217// FunctionWorkItem is a temporary class. WorkItem should just be replaced by WTF::Function everywhere.
     218class FunctionWorkItem : private WorkItem {
     219    // We only allow WorkItem to create this.
     220    friend class WorkItem;
     221
     222    explicit FunctionWorkItem(const Function<void()>& function)
     223        : m_function(function)
     224    {
     225    }
     226
     227    virtual void execute()
     228    {
     229        m_function();
     230    }
     231
     232    Function<void()> m_function;
     233};
     234
     235inline PassOwnPtr<WorkItem> WorkItem::create(const Function<void()>& function)
     236{
     237    return adoptPtr(static_cast<WorkItem*>(new FunctionWorkItem(function)));
     238}
     239
    214240#endif // WorkItem_h
  • trunk/Source/WebKit2/Platform/WorkQueue.cpp

    r95901 r102866  
    4141}
    4242
     43void WorkQueue::dispatch(const Function<void()>& function)
     44{
     45    scheduleWork(WorkItem::create(function));
     46}
     47
    4348void WorkQueue::invalidate()
    4449{
  • trunk/Source/WebKit2/Platform/WorkQueue.h

    r101141 r102866  
    5353#endif
    5454
     55namespace WTF {
     56    template<typename> class Function;
     57}
     58using WTF::Function;
     59
    5560class WorkQueue {
    5661    WTF_MAKE_NONCOPYABLE(WorkQueue);
     
    5964    explicit WorkQueue(const char* name);
    6065    ~WorkQueue();
     66
     67    // Will dispatch the given function to run as soon as possible.
     68    void dispatch(const Function<void()>&);
     69
     70    // FIXME: Get rid of WorkItem everywhere.
    6171
    6272    // Will schedule the given work item to run as soon as possible.
  • trunk/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp

    r95901 r102866  
    4545    // Launch the process.
    4646    m_isLaunching = true;
    47     processLauncherWorkQueue().scheduleWork(WorkItem::create(this, &ProcessLauncher::launchProcess));
     47    processLauncherWorkQueue().dispatch(bind(&ProcessLauncher::launchProcess, this));
    4848}
    4949
Note: See TracChangeset for help on using the changeset viewer.