[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

andersca at apple.com andersca at apple.com
Wed Dec 22 13:53:09 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit e56459b1a273337e0b88ec4ac39586fd0dbb72e6
Author: andersca at apple.com <andersca at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Sep 28 21:00:15 2010 +0000

    Differentiate waitForSyncReply from waitForReply
    https://bugs.webkit.org/show_bug.cgi?id=46752
    
    Reviewed by Sam Weinig.
    
    Since waitForSyncReply is going to need to dispatch incoming sync messages while
    waiting for the correct reply, we need to add a new waitForSyncReply function that
    can do this.
    
    * Platform/CoreIPC/Connection.cpp:
    (CoreIPC::Connection::sendSyncMessage):
    Push the pending sync reply information on the m_pendingSyncReplies stack,
    send the message, wait for a reply and pop the information off the stack.
    
    (CoreIPC::Connection::waitForSyncReply):
    Block while waiting for a reply to the sync message with the given ID.
    
    (CoreIPC::Connection::processIncomingMessage):
    If the incoming message is a sync reply, set the didReceiveReply flag and the replyDecoder
    members in the pending sync reply and signal the client thread to wakeup.
    
    * Platform/CoreIPC/Connection.h:
    Add a stack of PendingSyncReply structs.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68559 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index f52d192..08e45ea 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,29 @@
+2010-09-28  Anders Carlsson  <andersca at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Differentiate waitForSyncReply from waitForReply
+        https://bugs.webkit.org/show_bug.cgi?id=46752
+
+        Since waitForSyncReply is going to need to dispatch incoming sync messages while
+        waiting for the correct reply, we need to add a new waitForSyncReply function that
+        can do this.
+
+        * Platform/CoreIPC/Connection.cpp:
+        (CoreIPC::Connection::sendSyncMessage):
+        Push the pending sync reply information on the m_pendingSyncReplies stack,
+        send the message, wait for a reply and pop the information off the stack.
+
+        (CoreIPC::Connection::waitForSyncReply):
+        Block while waiting for a reply to the sync message with the given ID.
+        
+        (CoreIPC::Connection::processIncomingMessage):
+        If the incoming message is a sync reply, set the didReceiveReply flag and the replyDecoder
+        members in the pending sync reply and signal the client thread to wakeup.
+
+        * Platform/CoreIPC/Connection.h:
+        Add a stack of PendingSyncReply structs.
+
 2010-09-28  Sam Weinig  <sam at webkit.org>
 
         Reviewed by Darin Adler and Dave Hyatt.
diff --git a/WebKit2/Platform/CoreIPC/Connection.cpp b/WebKit2/Platform/CoreIPC/Connection.cpp
index a2346c2..def7c41 100644
--- a/WebKit2/Platform/CoreIPC/Connection.cpp
+++ b/WebKit2/Platform/CoreIPC/Connection.cpp
@@ -157,17 +157,78 @@ PassOwnPtr<ArgumentDecoder> Connection::waitForMessage(MessageID messageID, uint
 
 PassOwnPtr<ArgumentDecoder> Connection::sendSyncMessage(MessageID messageID, uint64_t syncRequestID, PassOwnPtr<ArgumentEncoder> encoder, double timeout)
 {
+    // We only allow sending sync messages from the client run loop.
+    ASSERT(RunLoop::current() == m_clientRunLoop);
+
+    if (!isValid())
+        return 0;
+    
+    // Push the pending sync reply information on our stack.
+    {
+        MutexLocker locker(m_waitForSyncReplyMutex);
+        m_pendingSyncReplies.append(PendingSyncReply(syncRequestID));
+    }
+    
     // First send the message.
-    if (!sendMessage(messageID, encoder))
-        return PassOwnPtr<ArgumentDecoder>();
+    sendMessage(messageID, encoder);
+    
+    // Then wait for a reply.
+    OwnPtr<ArgumentDecoder> reply = waitForSyncReply(syncRequestID, timeout);
 
-    // Now wait for a reply and return it.
-    return waitForMessage(MessageID(CoreIPCMessage::SyncMessageReply), syncRequestID, timeout);
+    // Finally, pop the pending sync reply information.
+    {
+        MutexLocker locker(m_waitForSyncReplyMutex);
+        ASSERT(m_pendingSyncReplies.last().syncRequestID == syncRequestID);
+        m_pendingSyncReplies.removeLast();
+    }
+    
+    return reply.release();
+}
+
+PassOwnPtr<ArgumentDecoder> Connection::waitForSyncReply(uint64_t syncRequestID, double timeout)
+{
+    double absoluteTime = currentTime() + timeout;
+
+    bool timedOut = false;
+    while (!timedOut) {
+        MutexLocker locker(m_waitForSyncReplyMutex);
+
+        // First, check if there is a sync reply at the top of the stack.
+        ASSERT(!m_pendingSyncReplies.isEmpty());
+            
+        PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
+        ASSERT(pendingSyncReply.syncRequestID == syncRequestID);
+            
+        // We found the sync reply, return it.
+        if (pendingSyncReply.didReceiveReply)
+            return pendingSyncReply.releaseReplyDecoder();
+
+        // We didn't find a sync reply yet, keep waiting.
+        timedOut = !m_waitForSyncReplyCondition.timedWait(m_waitForSyncReplyMutex, absoluteTime);
+    }
+
+    // We timed out.
+    return 0;
 }
 
 void Connection::processIncomingMessage(MessageID messageID, PassOwnPtr<ArgumentDecoder> arguments)
 {
-    // First, check if we're waiting for this message.
+    // Check if this is a sync reply.
+    if (messageID == MessageID(CoreIPCMessage::SyncMessageReply)) {
+        MutexLocker locker(m_waitForSyncReplyMutex);
+        ASSERT(!m_pendingSyncReplies.isEmpty());
+
+        PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
+        ASSERT(pendingSyncReply.syncRequestID == arguments->destinationID());
+
+        pendingSyncReply.replyDecoder = arguments.leakPtr();
+        pendingSyncReply.didReceiveReply = true;
+
+        m_waitForSyncReplyCondition.signal();
+        return;
+    }
+    
+    // Check if we're waiting for this message.
     {
         MutexLocker locker(m_waitForMessageMutex);
         
diff --git a/WebKit2/Platform/CoreIPC/Connection.h b/WebKit2/Platform/CoreIPC/Connection.h
index 9b2519b..a6b2161 100644
--- a/WebKit2/Platform/CoreIPC/Connection.h
+++ b/WebKit2/Platform/CoreIPC/Connection.h
@@ -151,9 +151,11 @@ private:
     
     bool isValid() const { return m_client; }
     
-    PassOwnPtr<ArgumentDecoder> sendSyncMessage(MessageID, uint64_t syncRequestID, PassOwnPtr<ArgumentEncoder>, double timeout);
     PassOwnPtr<ArgumentDecoder> waitForMessage(MessageID, uint64_t destinationID, double timeout);
     
+    PassOwnPtr<ArgumentDecoder> sendSyncMessage(MessageID, uint64_t syncRequestID, PassOwnPtr<ArgumentEncoder>, double timeout);
+    PassOwnPtr<ArgumentDecoder> waitForSyncReply(uint64_t syncRequestID, double timeout);
+
     // Called on the connection work queue.
     void processIncomingMessage(MessageID, PassOwnPtr<ArgumentDecoder>);
     bool canSendOutgoingMessages() const;
@@ -187,7 +189,49 @@ private:
     ThreadCondition m_waitForMessageCondition;
     Mutex m_waitForMessageMutex;
     HashMap<std::pair<unsigned, uint64_t>, ArgumentDecoder*> m_waitForMessageMap;
+
+    // Represents a sync request for which we're waiting on a reply.
+    struct PendingSyncReply {
+        // The request ID.
+        uint64_t syncRequestID;
+
+        // The reply decoder, will be null if there was an error processing the sync
+        // message on the other side.
+        ArgumentDecoder* replyDecoder;
+
+        // Will be set to true once a reply has been received or an error occurred.
+        bool didReceiveReply;
     
+        PendingSyncReply()
+            : syncRequestID(0)
+            , replyDecoder(0)
+            , didReceiveReply(false)
+        {
+        }
+
+        explicit PendingSyncReply(uint64_t syncRequestID)
+            : syncRequestID(syncRequestID)
+            , replyDecoder(0)
+            , didReceiveReply(0)
+        {
+        }
+
+        PassOwnPtr<ArgumentDecoder> releaseReplyDecoder()
+        {
+            OwnPtr<ArgumentDecoder> reply = adoptPtr(replyDecoder);
+            replyDecoder = 0;
+            
+            return reply.release();
+        }
+    };
+
+
+    Mutex m_waitForSyncReplyMutex;
+    ThreadCondition m_waitForSyncReplyCondition;
+
+    // This is protected by the m_waitForSyncReply mutex.    
+    Vector<PendingSyncReply> m_pendingSyncReplies;
+
 #if PLATFORM(MAC)
     // Called on the connection queue.
     void receiveSourceEventHandler();

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list