Bug 1202468 - remove mPendingQ lock r=dragana
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 23 May 2016 12:20:58 -0400
changeset 337778 fd50e33b4e9b825b4634fc79db5631defa3b88b7
parent 337777 798980ddb7803af375bdbfe59aa4a065c6af746e
child 337779 bece6d2a5793234b26afab6c1217ecffa3a2f1b2
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1202468
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1202468 - remove mPendingQ lock r=dragana
netwerk/base/nsSocketTransportService2.cpp
netwerk/base/nsSocketTransportService2.h
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -100,18 +100,16 @@ nsSocketTransportService::nsSocketTransp
     , mGoingOffline(false)
     , mRawThread(nullptr)
     , mActiveListSize(SOCKET_LIMIT_MIN)
     , mIdleListSize(SOCKET_LIMIT_MIN)
     , mActiveCount(0)
     , mIdleCount(0)
     , mSentBytesCount(0)
     , mReceivedBytesCount(0)
-    , mEventQueueLock("nsSocketTransportService::mEventQueueLock")
-    , mPendingSocketQ(mEventQueueLock)
     , mSendBufferSize(0)
     , mKeepaliveIdleTimeS(600)
     , mKeepaliveRetryIntervalS(1)
     , mKeepaliveProbeCount(kDefaultTCPKeepCount)
     , mKeepaliveEnabledPref(false)
     , mServingPendingQueue(false)
     , mMaxTimePerPollIter(100)
     , mTelemetryEnabledPref(false)
@@ -202,20 +200,18 @@ nsSocketTransportService::NotifyWhenCanA
     SOCKET_LOG(("nsSocketTransportService::NotifyWhenCanAttachSocket\n"));
 
     NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
 
     if (CanAttachSocket()) {
         return Dispatch(event, NS_DISPATCH_NORMAL);
     }
 
-    {
-      MutexAutoLock lock(mEventQueueLock);
-      mPendingSocketQ.PutEvent(event, lock);
-    }
+    LinkedRunnableEvent *runnable = new LinkedRunnableEvent(event);
+    mPendingSocketQueue.insertBack(runnable);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::AttachSocket(PRFileDesc *fd, nsASocketHandler *handler)
 {
     SOCKET_LOG(("nsSocketTransportService::AttachSocket [handler=%p]\n", handler));
 
@@ -281,19 +277,21 @@ nsSocketTransportService::DetachSocket(S
         RemoveFromIdleList(sock);
 
     // NOTE: sock is now an invalid pointer
     
     //
     // notify the first element on the pending socket queue...
     //
     nsCOMPtr<nsIRunnable> event;
-    {
-      MutexAutoLock lock(mEventQueueLock);
-      mPendingSocketQ.GetPendingEvent(getter_AddRefs(event), lock);
+    LinkedRunnableEvent *runnable = mPendingSocketQueue.getFirst();
+    if (runnable) {
+        event = runnable->TakeEvent();
+        runnable->remove();
+        delete runnable;
     }
     if (event) {
         // move event from pending queue to dispatch queue
         return Dispatch(event, NS_DISPATCH_NORMAL);
     }
     return NS_OK;
 }
 
--- a/netwerk/base/nsSocketTransportService2.h
+++ b/netwerk/base/nsSocketTransportService2.h
@@ -10,16 +10,17 @@
 #include "nsIThreadInternal.h"
 #include "nsIRunnable.h"
 #include "nsEventQueue.h"
 #include "nsCOMPtr.h"
 #include "prinrval.h"
 #include "mozilla/Logging.h"
 #include "prinit.h"
 #include "nsIObserver.h"
+#include "mozilla/LinkedList.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/net/DashboardTypes.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/TimeStamp.h"
 #include "nsITimer.h"
 #include "mozilla/UniquePtr.h"
 #include "PollableEvent.h"
 
@@ -60,16 +61,30 @@ static const int32_t kDefaultTCPKeepCoun
 #if defined (XP_WIN)
                                               10; // Hardcoded in Windows.
 #elif defined (XP_MACOSX)
                                               8;  // Hardcoded in OSX.
 #else
                                               4;  // Specifiable in Linux.
 #endif
 
+class LinkedRunnableEvent final : public LinkedListElement<LinkedRunnableEvent>
+{
+public:
+  explicit LinkedRunnableEvent(nsIRunnable *event) : mEvent(event) {}
+  ~LinkedRunnableEvent() {}
+
+  already_AddRefed<nsIRunnable> TakeEvent()
+  {
+    return mEvent.forget();
+  }
+private:
+    nsCOMPtr<nsIRunnable> mEvent;
+};
+
 //-----------------------------------------------------------------------------
 
 class nsSocketTransportService final : public nsPISocketTransportService
                                      , public nsIEventTarget
                                      , public nsIThreadObserver
                                      , public nsIRunnable
                                      , public nsIObserver
 {
@@ -197,19 +212,17 @@ private:
                                              // interval indicates the poll
                                              // duration in seconds.
                                              // pollDuration is used only for
                                              // telemetry
 
     //-------------------------------------------------------------------------
     // pending socket queue - see NotifyWhenCanAttachSocket
     //-------------------------------------------------------------------------
-
-    Mutex        mEventQueueLock;
-    nsEventQueue mPendingSocketQ; // queue of nsIRunnable objects
+    AutoCleanLinkedList<LinkedRunnableEvent> mPendingSocketQueue;
 
     // Preference Monitor for SendBufferSize and Keepalive prefs.
     nsresult    UpdatePrefs();
     void        UpdateSendBufferPref(nsIPrefBranch *);
     int32_t     mSendBufferSize;
     // Number of seconds of connection is idle before first keepalive ping.
     int32_t     mKeepaliveIdleTimeS;
     // Number of seconds between retries should keepalive pings fail.