⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185843 in webkit


Ignore:
Timestamp:
Jun 22, 2015, 2:11:25 PM (11 years ago)
Author:
andersca@apple.com
Message:

Simplify Connection::SyncMessageState
https://bugs.webkit.org/show_bug.cgi?id=146213

Reviewed by Andreas Kling.

Since we no longer support Connections dispatching to multiple threads, we can make SyncMessageState
into a singleton and get rid of the RunLoop -> SyncMessageState hash map.

  • Platform/IPC/Connection.cpp:

(IPC::Connection::SyncMessageState::singleton):
(IPC::Connection::SyncMessageState::SyncMessageState):
(IPC::Connection::SyncMessageState::processIncomingMessage):
(IPC::Connection::SyncMessageState::dispatchMessages):
(IPC::Connection::waitForSyncReply):
(IPC::Connection::processIncomingSyncReply):
(IPC::Connection::processIncomingMessage):
(IPC::Connection::connectionDidClose):
(IPC::Connection::SyncMessageState::syncMessageStateMap): Deleted.
(IPC::Connection::SyncMessageState::syncMessageStateMapMutex): Deleted.
(IPC::Connection::SyncMessageState::getOrCreate): Deleted.
(IPC::Connection::SyncMessageState::~SyncMessageState): Deleted.
(IPC::Connection::Connection): Deleted.

  • Platform/IPC/Connection.h:
Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r185840 r185843  
     12015-06-22  Anders Carlsson  <andersca@apple.com>
     2
     3        Simplify Connection::SyncMessageState
     4        https://bugs.webkit.org/show_bug.cgi?id=146213
     5
     6        Reviewed by Andreas Kling.
     7
     8        Since we no longer support Connections dispatching to multiple threads, we can make SyncMessageState
     9        into a singleton and get rid of the RunLoop -> SyncMessageState hash map.
     10
     11        * Platform/IPC/Connection.cpp:
     12        (IPC::Connection::SyncMessageState::singleton):
     13        (IPC::Connection::SyncMessageState::SyncMessageState):
     14        (IPC::Connection::SyncMessageState::processIncomingMessage):
     15        (IPC::Connection::SyncMessageState::dispatchMessages):
     16        (IPC::Connection::waitForSyncReply):
     17        (IPC::Connection::processIncomingSyncReply):
     18        (IPC::Connection::processIncomingMessage):
     19        (IPC::Connection::connectionDidClose):
     20        (IPC::Connection::SyncMessageState::syncMessageStateMap): Deleted.
     21        (IPC::Connection::SyncMessageState::syncMessageStateMapMutex): Deleted.
     22        (IPC::Connection::SyncMessageState::getOrCreate): Deleted.
     23        (IPC::Connection::SyncMessageState::~SyncMessageState): Deleted.
     24        (IPC::Connection::Connection): Deleted.
     25        * Platform/IPC/Connection.h:
     26
    1272015-06-20  Alex Christensen  <achristensen@webkit.org>
    228
  • trunk/Source/WebKit2/Platform/IPC/Connection.cpp

    r185839 r185843  
    5656};
    5757
    58 class Connection::SyncMessageState : public ThreadSafeRefCounted<Connection::SyncMessageState> {
     58class Connection::SyncMessageState {
    5959public:
    60     static Ref<SyncMessageState> getOrCreate(RunLoop&);
    61     ~SyncMessageState();
     60    static SyncMessageState& singleton();
     61
     62    SyncMessageState();
     63    ~SyncMessageState() = delete;
    6264
    6365    void wakeUpClientRunLoop()
     
    8082
    8183private:
    82     explicit SyncMessageState(RunLoop&);
    83 
    84     typedef HashMap<RunLoop*, SyncMessageState*> SyncMessageStateMap;
    85     static SyncMessageStateMap& syncMessageStateMap()
    86     {
    87         static NeverDestroyed<SyncMessageStateMap> syncMessageStateMap;
    88         return syncMessageStateMap;
    89     }
    90 
    91     static std::mutex& syncMessageStateMapMutex()
    92     {
    93         static LazyNeverDestroyed<std::mutex> syncMessageStateMapMutex;
    94         static std::once_flag onceFlag;
    95         std::call_once(onceFlag, [] {
    96             syncMessageStateMapMutex.construct();
    97         });
    98 
    99         return syncMessageStateMapMutex;
    100     }
    101 
    10284    void dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(Connection&);
    10385
    104     RunLoop& m_runLoop;
    10586    BinarySemaphore m_waitForSyncReplySemaphore;
    10687
     
    127108
    128109
    129 Ref<Connection::SyncMessageState> Connection::SyncMessageState::getOrCreate(RunLoop& runLoop)
    130 {
    131     std::lock_guard<std::mutex> lock(syncMessageStateMapMutex());
    132 
    133     auto& slot = syncMessageStateMap().add(&runLoop, nullptr).iterator->value;
    134     if (slot)
    135         return *slot;
    136 
    137     Ref<SyncMessageState> syncMessageState = adoptRef(*new SyncMessageState(runLoop));
    138     slot = syncMessageState.ptr();
     110Connection::SyncMessageState& Connection::SyncMessageState::singleton()
     111{
     112    static std::once_flag onceFlag;
     113    static LazyNeverDestroyed<SyncMessageState> syncMessageState;
     114
     115    std::call_once(onceFlag, [] {
     116        syncMessageState.construct();
     117    });
    139118
    140119    return syncMessageState;
    141120}
    142121
    143 Connection::SyncMessageState::SyncMessageState(RunLoop& runLoop)
    144     : m_runLoop(runLoop)
    145 {
    146 }
    147 
    148 Connection::SyncMessageState::~SyncMessageState()
    149 {
    150     std::lock_guard<std::mutex> lock(syncMessageStateMapMutex());
    151 
    152     ASSERT(syncMessageStateMap().contains(&m_runLoop));
    153     syncMessageStateMap().remove(&m_runLoop);
    154 
    155     ASSERT(m_messagesToDispatchWhileWaitingForSyncReply.isEmpty());
     122Connection::SyncMessageState::SyncMessageState()
     123{
    156124}
    157125
     
    168136        if (m_didScheduleDispatchMessagesWorkSet.add(&connection).isNewEntry) {
    169137            RefPtr<Connection> protectedConnection(&connection);
    170             m_runLoop.dispatch([this, protectedConnection] {
     138            RunLoop::main().dispatch([this, protectedConnection] {
    171139                dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(*protectedConnection);
    172140            });
     
    183151void Connection::SyncMessageState::dispatchMessages(Connection* allowedConnection)
    184152{
    185     ASSERT(&m_runLoop == &RunLoop::current());
     153    ASSERT(RunLoop::isMain());
    186154
    187155    Vector<ConnectionAndIncomingMessage> messagesToDispatchWhileWaitingForSyncReply;
     
    250218    , m_didReceiveInvalidMessage(false)
    251219    , m_waitingForMessage(nullptr)
    252     , m_syncMessageState(SyncMessageState::getOrCreate(RunLoop::main()))
    253220    , m_shouldWaitForSyncReplies(true)
    254221{
     
    577544    while (!timedOut) {
    578545        // First, check if we have any messages that we need to process.
    579         m_syncMessageState->dispatchMessages(nullptr);
     546        SyncMessageState::singleton().dispatchMessages(nullptr);
    580547       
    581548        {
     
    615582#endif
    616583        } else
    617             timedOut = !m_syncMessageState->wait(absoluteTime);
     584            timedOut = !SyncMessageState::singleton().wait(absoluteTime);
    618585       
    619586    }
     
    643610        // We got a reply to the last send message, wake up the client run loop so it can be processed.
    644611        if (i == m_pendingSyncReplies.size())
    645             m_syncMessageState->wakeUpClientRunLoop();
     612            SyncMessageState::singleton().wakeUpClientRunLoop();
    646613
    647614        return;
     
    706673    // a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched.
    707674    // If we don't we'll end up with a deadlock where both sync message senders are stuck waiting for a reply.
    708     if (m_syncMessageState->processIncomingMessage(*this, message))
     675    if (SyncMessageState::singleton().processIncomingMessage(*this, message))
    709676        return;
    710677
     
    749716
    750717        if (!m_pendingSyncReplies.isEmpty())
    751             m_syncMessageState->wakeUpClientRunLoop();
     718            SyncMessageState::singleton().wakeUpClientRunLoop();
    752719
    753720        for (SecondaryThreadPendingSyncReplyMap::iterator iter = m_secondaryThreadPendingSyncReplyMap.begin(); iter != m_secondaryThreadPendingSyncReplyMap.end(); ++iter)
  • trunk/Source/WebKit2/Platform/IPC/Connection.h

    r185839 r185843  
    294294    class SyncMessageState;
    295295    friend class SyncMessageState;
    296     RefPtr<SyncMessageState> m_syncMessageState;
    297296
    298297    Mutex m_syncReplyStateMutex;
Note: See TracChangeset for help on using the changeset viewer.