Modified: trunk/Source/WebKit2/ChangeLog (185842 => 185843)
--- trunk/Source/WebKit2/ChangeLog 2015-06-22 20:53:26 UTC (rev 185842)
+++ trunk/Source/WebKit2/ChangeLog 2015-06-22 21:11:25 UTC (rev 185843)
@@ -1,3 +1,29 @@
+2015-06-22 Anders Carlsson <ander...@apple.com>
+
+ 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:
+
2015-06-20 Alex Christensen <achristen...@webkit.org>
[Content Extensions] Add SPI to reload without content blocking.
Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (185842 => 185843)
--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp 2015-06-22 20:53:26 UTC (rev 185842)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp 2015-06-22 21:11:25 UTC (rev 185843)
@@ -55,11 +55,13 @@
std::unique_ptr<MessageDecoder> decoder;
};
-class Connection::SyncMessageState : public ThreadSafeRefCounted<Connection::SyncMessageState> {
+class Connection::SyncMessageState {
public:
- static Ref<SyncMessageState> getOrCreate(RunLoop&);
- ~SyncMessageState();
+ static SyncMessageState& singleton();
+ SyncMessageState();
+ ~SyncMessageState() = delete;
+
void wakeUpClientRunLoop()
{
m_waitForSyncReplySemaphore.signal();
@@ -79,29 +81,8 @@
void dispatchMessages(Connection* allowedConnection);
private:
- explicit SyncMessageState(RunLoop&);
-
- typedef HashMap<RunLoop*, SyncMessageState*> SyncMessageStateMap;
- static SyncMessageStateMap& syncMessageStateMap()
- {
- static NeverDestroyed<SyncMessageStateMap> syncMessageStateMap;
- return syncMessageStateMap;
- }
-
- static std::mutex& syncMessageStateMapMutex()
- {
- static LazyNeverDestroyed<std::mutex> syncMessageStateMapMutex;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [] {
- syncMessageStateMapMutex.construct();
- });
-
- return syncMessageStateMapMutex;
- }
-
void dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(Connection&);
- RunLoop& m_runLoop;
BinarySemaphore m_waitForSyncReplySemaphore;
// Protects m_didScheduleDispatchMessagesWorkSet and m_messagesToDispatchWhileWaitingForSyncReply.
@@ -126,35 +107,22 @@
};
-Ref<Connection::SyncMessageState> Connection::SyncMessageState::getOrCreate(RunLoop& runLoop)
+Connection::SyncMessageState& Connection::SyncMessageState::singleton()
{
- std::lock_guard<std::mutex> lock(syncMessageStateMapMutex());
+ static std::once_flag onceFlag;
+ static LazyNeverDestroyed<SyncMessageState> syncMessageState;
- auto& slot = syncMessageStateMap().add(&runLoop, nullptr).iterator->value;
- if (slot)
- return *slot;
+ std::call_once(onceFlag, [] {
+ syncMessageState.construct();
+ });
- Ref<SyncMessageState> syncMessageState = adoptRef(*new SyncMessageState(runLoop));
- slot = syncMessageState.ptr();
-
return syncMessageState;
}
-Connection::SyncMessageState::SyncMessageState(RunLoop& runLoop)
- : m_runLoop(runLoop)
+Connection::SyncMessageState::SyncMessageState()
{
}
-Connection::SyncMessageState::~SyncMessageState()
-{
- std::lock_guard<std::mutex> lock(syncMessageStateMapMutex());
-
- ASSERT(syncMessageStateMap().contains(&m_runLoop));
- syncMessageStateMap().remove(&m_runLoop);
-
- ASSERT(m_messagesToDispatchWhileWaitingForSyncReply.isEmpty());
-}
-
bool Connection::SyncMessageState::processIncomingMessage(Connection& connection, std::unique_ptr<MessageDecoder>& message)
{
if (!message->shouldDispatchMessageWhenWaitingForSyncReply())
@@ -167,7 +135,7 @@
if (m_didScheduleDispatchMessagesWorkSet.add(&connection).isNewEntry) {
RefPtr<Connection> protectedConnection(&connection);
- m_runLoop.dispatch([this, protectedConnection] {
+ RunLoop::main().dispatch([this, protectedConnection] {
dispatchMessageAndResetDidScheduleDispatchMessagesForConnection(*protectedConnection);
});
}
@@ -182,7 +150,7 @@
void Connection::SyncMessageState::dispatchMessages(Connection* allowedConnection)
{
- ASSERT(&m_runLoop == &RunLoop::current());
+ ASSERT(RunLoop::isMain());
Vector<ConnectionAndIncomingMessage> messagesToDispatchWhileWaitingForSyncReply;
@@ -249,7 +217,6 @@
, m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount(0)
, m_didReceiveInvalidMessage(false)
, m_waitingForMessage(nullptr)
- , m_syncMessageState(SyncMessageState::getOrCreate(RunLoop::main()))
, m_shouldWaitForSyncReplies(true)
{
ASSERT(RunLoop::isMain());
@@ -576,7 +543,7 @@
bool timedOut = false;
while (!timedOut) {
// First, check if we have any messages that we need to process.
- m_syncMessageState->dispatchMessages(nullptr);
+ SyncMessageState::singleton().dispatchMessages(nullptr);
{
MutexLocker locker(m_syncReplyStateMutex);
@@ -614,7 +581,7 @@
timedOut = currentTime() >= absoluteTime;
#endif
} else
- timedOut = !m_syncMessageState->wait(absoluteTime);
+ timedOut = !SyncMessageState::singleton().wait(absoluteTime);
}
@@ -642,7 +609,7 @@
// We got a reply to the last send message, wake up the client run loop so it can be processed.
if (i == m_pendingSyncReplies.size())
- m_syncMessageState->wakeUpClientRunLoop();
+ SyncMessageState::singleton().wakeUpClientRunLoop();
return;
}
@@ -705,7 +672,7 @@
// Check if this is a sync message or if it's a message that should be dispatched even when waiting for
// a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched.
// If we don't we'll end up with a deadlock where both sync message senders are stuck waiting for a reply.
- if (m_syncMessageState->processIncomingMessage(*this, message))
+ if (SyncMessageState::singleton().processIncomingMessage(*this, message))
return;
// Check if we're waiting for this message.
@@ -748,7 +715,7 @@
m_shouldWaitForSyncReplies = false;
if (!m_pendingSyncReplies.isEmpty())
- m_syncMessageState->wakeUpClientRunLoop();
+ SyncMessageState::singleton().wakeUpClientRunLoop();
for (SecondaryThreadPendingSyncReplyMap::iterator iter = m_secondaryThreadPendingSyncReplyMap.begin(); iter != m_secondaryThreadPendingSyncReplyMap.end(); ++iter)
iter->value->semaphore.signal();
Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (185842 => 185843)
--- trunk/Source/WebKit2/Platform/IPC/Connection.h 2015-06-22 20:53:26 UTC (rev 185842)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h 2015-06-22 21:11:25 UTC (rev 185843)
@@ -293,7 +293,6 @@
class SyncMessageState;
friend class SyncMessageState;
- RefPtr<SyncMessageState> m_syncMessageState;
Mutex m_syncReplyStateMutex;
bool m_shouldWaitForSyncReplies;