Bug 559200 - Follow up to remove unsafe locking r=dougt
authorJosh Matthews <josh@joshmatthews.net>
Wed, 04 Aug 2010 16:13:12 -0700
changeset 48879 b22036de463abb4a9599467ed3ade634aee953c0
parent 48878 267f561c325aaa03bef6bf5157ceea8f97a39000
child 48880 d59ad0384708fcb57463e32fc878f6576dd8cb7f
push idunknown
push userunknown
push dateunknown
reviewersdougt
bugs559200
milestone2.0b4pre
Bug 559200 - Follow up to remove unsafe locking r=dougt
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelChild.h
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -44,18 +44,16 @@
 #include "mozilla/net/NeckoChild.h"
 #include "mozilla/net/HttpChannelChild.h"
 
 #include "nsStringStream.h"
 #include "nsHttpHandler.h"
 #include "nsMimeTypes.h"
 #include "nsNetUtil.h"
 
-using mozilla::MutexAutoLock;
-
 class Callback
 {
  public:
   virtual bool Run() = 0;
 };
 
 namespace mozilla {
 namespace net {
@@ -63,17 +61,16 @@ namespace net {
 // C++ file contents
 HttpChannelChild::HttpChannelChild()
   : mIsFromCache(PR_FALSE)
   , mCacheEntryAvailable(PR_FALSE)
   , mCacheExpirationTime(nsICache::NO_EXPIRATION_TIME)
   , mState(HCC_NEW)
   , mIPCOpen(false)
   , mShouldBuffer(true)
-  , mBufferLock("mozilla.net.HttpChannelChild.mBufferLock")
 {
   LOG(("Creating HttpChannelChild @%x\n", this));
 }
 
 HttpChannelChild::~HttpChannelChild()
 {
   LOG(("Destroying HttpChannelChild @%x\n", this));
 }
@@ -151,17 +148,16 @@ HttpChannelChild::RecvOnStartRequest(con
     //  - make sure we do call OnStopRequest eventually
     //  - return true here, not false
     return false;  
   }
 
   if (mResponseHead)
     SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie));
 
-  MutexAutoLock lock(mBufferLock);
   bool ret = true;
   nsCOMPtr<nsIHttpChannel> kungFuDeathGrip(this);
   for (PRUint32 i = 0; i < mBufferedCallbacks.Length(); i++) {
     ret = mBufferedCallbacks[i]->Run();
     if (!ret)
       break;
   }
   mBufferedCallbacks.Clear();
@@ -384,24 +380,18 @@ HttpChannelChild::OnStatus(const nsresul
 
   return true;
 }
 
 bool
 HttpChannelChild::BufferOrDispatch(Callback* callback)
 {
   if (mShouldBuffer) {
-    MutexAutoLock lock(mBufferLock);
-    // If we can't grab the lock immediately, that means we're currently
-    // emptying the buffer. Therefore, the following condition should now
-    // be false, and we can resume immediate message processing.
-    if (mShouldBuffer) {
       mBufferedCallbacks.AppendElement(callback);
       return true;
-    }
   }
 
   bool result = callback->Run();
   delete callback;
   return result;
 }
 
 //-----------------------------------------------------------------------------
--- a/netwerk/protocol/http/HttpChannelChild.h
+++ b/netwerk/protocol/http/HttpChannelChild.h
@@ -147,17 +147,16 @@ private:
   // FIXME: replace with IPDL states (bug 536319) 
   enum HttpChannelChildState mState;
   bool mIPCOpen;
 
   // Workaround for Necko re-entrancy dangers. We buffer all messages
   // received until OnStartRequest completes.
   nsTArray<nsAutoPtr<Callback> > mBufferedCallbacks;
   bool mShouldBuffer;
-  mozilla::Mutex mBufferLock;
 
   bool BufferOrDispatch(Callback* callback);
 
   // This class does not actually implement the stream listener interface.
   // These functions actually perform the actions associated with the
   // corresponding IPDL receivers above.
   bool OnDataAvailable(const nsCString& data, 
                        const PRUint32& offset,