diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-29 07:00:47 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-29 07:00:47 +0000 |
commit | a93885094715c2d23953f9139d61e1071d8006a5 (patch) | |
tree | 9fa47c8472e643e36b59717e7d01d67399d36785 /ipc | |
parent | 813076634b1a26300428247a735629ecde96b93c (diff) | |
download | chromium_src-a93885094715c2d23953f9139d61e1071d8006a5.zip chromium_src-a93885094715c2d23953f9139d61e1071d8006a5.tar.gz chromium_src-a93885094715c2d23953f9139d61e1071d8006a5.tar.bz2 |
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
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_sync_message_filter.cc | 14 | ||||
-rw-r--r-- | ipc/ipc_sync_message_filter.h | 17 |
2 files changed, 9 insertions, 22 deletions
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 <set> 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<MessageLoop*> { - size_t operator()(MessageLoop* message_loop) const { - return reinterpret_cast<size_t>(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<MessageLoop*, PendingSyncMsg*> PendingSyncMessages; + typedef std::set<PendingSyncMsg*> PendingSyncMessages; PendingSyncMessages pending_sync_messages_; // Locks data members above. |