Changeset 185843 in webkit
- Timestamp:
- Jun 22, 2015, 2:11:25 PM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
Platform/IPC/Connection.cpp (modified) (11 diffs)
-
Platform/IPC/Connection.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r185840 r185843 1 2015-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 1 27 2015-06-20 Alex Christensen <achristensen@webkit.org> 2 28 -
trunk/Source/WebKit2/Platform/IPC/Connection.cpp
r185839 r185843 56 56 }; 57 57 58 class Connection::SyncMessageState : public ThreadSafeRefCounted<Connection::SyncMessageState>{58 class Connection::SyncMessageState { 59 59 public: 60 static Ref<SyncMessageState> getOrCreate(RunLoop&); 61 ~SyncMessageState(); 60 static SyncMessageState& singleton(); 61 62 SyncMessageState(); 63 ~SyncMessageState() = delete; 62 64 63 65 void wakeUpClientRunLoop() … … 80 82 81 83 private: 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 102 84 void dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(Connection&); 103 85 104 RunLoop& m_runLoop;105 86 BinarySemaphore m_waitForSyncReplySemaphore; 106 87 … … 127 108 128 109 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(); 110 Connection::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 }); 139 118 140 119 return syncMessageState; 141 120 } 142 121 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()); 122 Connection::SyncMessageState::SyncMessageState() 123 { 156 124 } 157 125 … … 168 136 if (m_didScheduleDispatchMessagesWorkSet.add(&connection).isNewEntry) { 169 137 RefPtr<Connection> protectedConnection(&connection); 170 m_runLoop.dispatch([this, protectedConnection] {138 RunLoop::main().dispatch([this, protectedConnection] { 171 139 dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(*protectedConnection); 172 140 }); … … 183 151 void Connection::SyncMessageState::dispatchMessages(Connection* allowedConnection) 184 152 { 185 ASSERT( &m_runLoop == &RunLoop::current());153 ASSERT(RunLoop::isMain()); 186 154 187 155 Vector<ConnectionAndIncomingMessage> messagesToDispatchWhileWaitingForSyncReply; … … 250 218 , m_didReceiveInvalidMessage(false) 251 219 , m_waitingForMessage(nullptr) 252 , m_syncMessageState(SyncMessageState::getOrCreate(RunLoop::main()))253 220 , m_shouldWaitForSyncReplies(true) 254 221 { … … 577 544 while (!timedOut) { 578 545 // First, check if we have any messages that we need to process. 579 m_syncMessageState->dispatchMessages(nullptr);546 SyncMessageState::singleton().dispatchMessages(nullptr); 580 547 581 548 { … … 615 582 #endif 616 583 } else 617 timedOut = ! m_syncMessageState->wait(absoluteTime);584 timedOut = !SyncMessageState::singleton().wait(absoluteTime); 618 585 619 586 } … … 643 610 // We got a reply to the last send message, wake up the client run loop so it can be processed. 644 611 if (i == m_pendingSyncReplies.size()) 645 m_syncMessageState->wakeUpClientRunLoop();612 SyncMessageState::singleton().wakeUpClientRunLoop(); 646 613 647 614 return; … … 706 673 // a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched. 707 674 // 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)) 709 676 return; 710 677 … … 749 716 750 717 if (!m_pendingSyncReplies.isEmpty()) 751 m_syncMessageState->wakeUpClientRunLoop();718 SyncMessageState::singleton().wakeUpClientRunLoop(); 752 719 753 720 for (SecondaryThreadPendingSyncReplyMap::iterator iter = m_secondaryThreadPendingSyncReplyMap.begin(); iter != m_secondaryThreadPendingSyncReplyMap.end(); ++iter) -
trunk/Source/WebKit2/Platform/IPC/Connection.h
r185839 r185843 294 294 class SyncMessageState; 295 295 friend class SyncMessageState; 296 RefPtr<SyncMessageState> m_syncMessageState;297 296 298 297 Mutex m_syncReplyStateMutex;
Note:
See TracChangeset
for help on using the changeset viewer.