From a93885094715c2d23953f9139d61e1071d8006a5 Mon Sep 17 00:00:00 2001 From: "dumi@chromium.org" Date: Sat, 29 May 2010 07:00:47 +0000 Subject: Make SyncMessageFilter work with WebKit threads. SyncMessageFilter doesn't work with WebKit threads, because WebKit threads don't have MessageLoops, so two threads send a message at the same time, the first thread will stay blocked forever. Also, it's unclear why we need to use MessageLoops as keys in a hash_maps. The code doesn't use them at all. TEST=a DB example that used to deadlock is working now BUG=45253 Review URL: http://codereview.chromium.org/2360003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48556 0039d316-1c4b-4281-b951-d872f2087c98 --- ipc/ipc_sync_message_filter.cc | 14 +++++++------- ipc/ipc_sync_message_filter.h | 17 ++--------------- 2 files changed, 9 insertions(+), 22 deletions(-) (limited to 'ipc') diff --git a/ipc/ipc_sync_message_filter.cc b/ipc/ipc_sync_message_filter.cc index db3f86e..6a719f9 100644 --- a/ipc/ipc_sync_message_filter.cc +++ b/ipc/ipc_sync_message_filter.cc @@ -48,7 +48,7 @@ bool SyncMessageFilter::Send(Message* message) { // Also by definition, can't use this on IO thread since we're blocking it. DCHECK(MessageLoop::current() != listener_loop_); DCHECK(MessageLoop::current() != io_loop_); - pending_sync_messages_[MessageLoop::current()] = &pending_message; + pending_sync_messages_.insert(&pending_message); } io_loop_->PostTask( @@ -61,7 +61,7 @@ bool SyncMessageFilter::Send(Message* message) { { AutoLock auto_lock(lock_); delete pending_message.deserializer; - pending_sync_messages_.erase(MessageLoop::current()); + pending_sync_messages_.erase(&pending_message); } return pending_message.send_result; @@ -86,7 +86,7 @@ void SyncMessageFilter::SignalAllEvents() { AutoLock auto_lock(lock_); for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); iter != pending_sync_messages_.end(); ++iter) { - iter->second->done_event->Signal(); + (*iter)->done_event->Signal(); } } @@ -110,12 +110,12 @@ bool SyncMessageFilter::OnMessageReceived(const Message& message) { AutoLock auto_lock(lock_); for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); iter != pending_sync_messages_.end(); ++iter) { - if (SyncMessage::IsMessageReplyTo(message, iter->second->id)) { + if (SyncMessage::IsMessageReplyTo(message, (*iter)->id)) { if (!message.is_reply_error()) { - iter->second->send_result = - iter->second->deserializer->SerializeOutputParameters(message); + (*iter)->send_result = + (*iter)->deserializer->SerializeOutputParameters(message); } - iter->second->done_event->Signal(); + (*iter)->done_event->Signal(); return true; } } diff --git a/ipc/ipc_sync_message_filter.h b/ipc/ipc_sync_message_filter.h index 71d24c1..87fd612 100644 --- a/ipc/ipc_sync_message_filter.h +++ b/ipc/ipc_sync_message_filter.h @@ -6,28 +6,15 @@ #define IPC_IPC_SYNC_MESSAGE_FILTER_H_ #include "base/basictypes.h" -#include "base/hash_tables.h" #include "base/lock.h" #include "base/ref_counted.h" #include "base/waitable_event.h" #include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_sync_message.h" +#include class MessageLoop; -#if defined(COMPILER_GCC) -// Allows us to use MessageLoop in a hash_map with gcc (MSVC is okay without -// specifying this). -namespace __gnu_cxx { -template<> -struct hash { - size_t operator()(MessageLoop* message_loop) const { - return reinterpret_cast(message_loop); - } -}; -} -#endif - namespace IPC { class MessageReplyDeserializer; @@ -63,7 +50,7 @@ class SyncMessageFilter : public ChannelProxy::MessageFilter, MessageLoop* listener_loop_; // The process's main thread. MessageLoop* io_loop_; // The message loop where the Channel lives. - typedef base::hash_map PendingSyncMessages; + typedef std::set PendingSyncMessages; PendingSyncMessages pending_sync_messages_; // Locks data members above. -- cgit v1.1