Bug 685435. imglib: Remove some unneeded multithread support. r=joe
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Mon, 19 Sep 2011 15:57:21 -0400
changeset 78510 b80b4d52cd14da737d775738c395ec13f17c26b1
parent 78509 d7bc56a9611ba7e62f4d123ffb05ee4e71d95d95
child 78511 812cea5c372e80d75f983d6cd0138ac1ccd6706e
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs685435
milestone9.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 685435. imglib: Remove some unneeded multithread support. r=joe imglib should only be called from the main thread which implies that we shouldn't need this stuff.
modules/libpr0n/src/imgLoader.cpp
modules/libpr0n/src/imgRequest.cpp
modules/libpr0n/src/imgRequest.h
--- a/modules/libpr0n/src/imgLoader.cpp
+++ b/modules/libpr0n/src/imgLoader.cpp
@@ -1054,22 +1054,16 @@ PRBool imgLoader::PutIntoCache(nsIURI *k
   // Check to see if this request already exists in the cache and is being
   // loaded on a different thread. If so, don't allow this entry to be added to
   // the cache.
   nsRefPtr<imgCacheEntry> tmpCacheEntry;
   if (cache.Get(spec, getter_AddRefs(tmpCacheEntry)) && tmpCacheEntry) {
     PR_LOG(gImgLog, PR_LOG_DEBUG,
            ("[this=%p] imgLoader::PutIntoCache -- Element already in the cache", nsnull));
     nsRefPtr<imgRequest> tmpRequest = getter_AddRefs(tmpCacheEntry->GetRequest());
-    void *cacheId = NS_GetCurrentThread();
-
-    // If the existing request is currently loading, or loading on a different
-    // thread, we'll leave it be, and not put this new entry into the cache.
-    if (!tmpRequest->IsReusable(cacheId))
-      return PR_FALSE;
 
     // If it already exists, and we're putting the same key into the cache, we
     // should remove the old version.
     PR_LOG(gImgLog, PR_LOG_DEBUG,
            ("[this=%p] imgLoader::PutIntoCache -- Replacing cached element", nsnull));
 
     RemoveFromCache(key);
   } else {
@@ -1392,36 +1386,16 @@ PRBool imgLoader::ValidateEntry(imgCache
     aURI->GetSpec(spec);
 
     PR_LOG(gImgLog, PR_LOG_DEBUG,
            ("imgLoader::ValidateEntry BYPASSING cache validation for %s " 
             "because of NULL LoadID", spec.get()));
   }
 #endif
 
-  //
-  // Get the current thread...  This is used as a cacheId to prevent
-  // sharing requests which are being loaded across multiple threads...
-  //
-  void *cacheId = NS_GetCurrentThread();
-  if (!request->IsReusable(cacheId)) {
-    //
-    // The current request is still being loaded and lives on a different
-    // event queue.
-    //
-    // Since its event queue is NOT active, do not reuse this imgRequest.
-    // PutIntoCache() will also ensure that we don't cache it.
-    //
-    PR_LOG(gImgLog, PR_LOG_DEBUG,
-           ("imgLoader::ValidateEntry -- DANGER!! Unable to use cached "
-            "imgRequest [request=%p]\n", address_of(request)));
-
-    return PR_FALSE;
-  }
-
   // We can't use a cached request if it comes from a different
   // application cache than this load is expecting.
   nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer;
   nsCOMPtr<nsIApplicationCache> requestAppCache;
   nsCOMPtr<nsIApplicationCache> groupAppCache;
   if ((appCacheContainer = do_GetInterface(request->mRequest)))
     appCacheContainer->GetApplicationCache(getter_AddRefs(requestAppCache));
   if ((appCacheContainer = do_QueryInterface(aLoadGroup)))
@@ -1700,18 +1674,17 @@ NS_IMETHODIMP imgLoader::LoadImage(nsIUR
            ("[this=%p] imgLoader::LoadImage -- Created new imgRequest [request=%p]\n", this, request.get()));
 
     // Create a loadgroup for this new channel.  This way if the channel
     // is redirected, we'll have a way to cancel the resulting channel.
     nsCOMPtr<nsILoadGroup> loadGroup =
         do_CreateInstance(NS_LOADGROUP_CONTRACTID);
     newChannel->SetLoadGroup(loadGroup);
 
-    void *cacheId = NS_GetCurrentThread();
-    request->Init(aURI, aURI, loadGroup, newChannel, entry, cacheId, aCX,
+    request->Init(aURI, aURI, loadGroup, newChannel, entry, aCX,
                   aLoadingPrincipal, corsmode);
 
     // Pass the inner window ID of the loading document, if possible.
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
     if (doc) {
       request->SetInnerWindowID(doc->InnerWindowID());
     }
 
@@ -1899,17 +1872,17 @@ NS_IMETHODIMP imgLoader::LoadImageWithCh
       return NS_ERROR_OUT_OF_MEMORY;
 
     // We use originalURI here to fulfil the imgIRequest contract on GetURI.
     nsCOMPtr<nsIURI> originalURI;
     channel->GetOriginalURI(getter_AddRefs(originalURI));
 
     // No principal specified here, because we're not passed one.
     request->Init(originalURI, uri, channel, channel, entry,
-                  NS_GetCurrentThread(), aCX, nsnull, imgIRequest::CORS_NONE);
+                  aCX, nsnull, imgIRequest::CORS_NONE);
 
     ProxyListener *pl = new ProxyListener(static_cast<nsIStreamListener *>(request.get()));
     NS_ADDREF(pl);
 
     *listener = static_cast<nsIStreamListener*>(pl);
     NS_ADDREF(*listener);
 
     NS_RELEASE(pl);
@@ -2206,17 +2179,17 @@ NS_IMETHODIMP imgCacheValidator::OnStart
 
   mRequest->mValidator = nsnull;
   mRequest = nsnull;
 
   // We use originalURI here to fulfil the imgIRequest contract on GetURI.
   nsCOMPtr<nsIURI> originalURI;
   channel->GetOriginalURI(getter_AddRefs(originalURI));
   mNewRequest->Init(originalURI, uri, channel, channel, mNewEntry,
-                    NS_GetCurrentThread(), mContext, loadingPrincipal,
+                    mContext, loadingPrincipal,
                     corsmode);
 
   mDestListener = new ProxyListener(mNewRequest);
 
   // Try to add the new request into the cache. Note that the entry must be in
   // the cache before the proxies' ownership changes, because adding a proxy
   // changes the caching behaviour for imgRequests.
   sImgLoader.PutIntoCache(originalURI, mNewEntry);
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -178,17 +178,17 @@ NS_IMPL_ISUPPORTS8(imgRequest,
                    imgIDecoderObserver, imgIContainerObserver,
                    nsIStreamListener, nsIRequestObserver,
                    nsISupportsWeakReference,
                    nsIChannelEventSink,
                    nsIInterfaceRequestor,
                    nsIAsyncVerifyRedirectCallback)
 
 imgRequest::imgRequest() : 
-  mCacheId(0), mValidator(nsnull), mImageSniffers("image-sniffing-services"),
+  mValidator(nsnull), mImageSniffers("image-sniffing-services"),
   mInnerWindowId(0), mCORSMode(imgIRequest::CORS_NONE),
   mDecodeRequested(PR_FALSE), mIsMultiPartChannel(PR_FALSE), mGotData(PR_FALSE),
   mIsInCache(PR_FALSE)
 {}
 
 imgRequest::~imgRequest()
 {
   if (mURI) {
@@ -199,17 +199,16 @@ imgRequest::~imgRequest()
     LOG_FUNC(gImgLog, "imgRequest::~imgRequest()");
 }
 
 nsresult imgRequest::Init(nsIURI *aURI,
                           nsIURI *aCurrentURI,
                           nsIRequest *aRequest,
                           nsIChannel *aChannel,
                           imgCacheEntry *aCacheEntry,
-                          void *aCacheId,
                           void *aLoadId,
                           nsIPrincipal* aLoadingPrincipal,
                           PRInt32 aCORSMode)
 {
   LOG_FUNC(gImgLog, "imgRequest::Init");
 
   NS_ABORT_IF_FALSE(!mImage, "Multiple calls to init");
   NS_ABORT_IF_FALSE(aURI, "No uri");
@@ -234,18 +233,16 @@ nsresult imgRequest::Init(nsIURI *aURI,
 
   NS_ASSERTION(mPrevChannelSink != this,
                "Initializing with a channel that already calls back to us!");
 
   mChannel->SetNotificationCallbacks(this);
 
   mCacheEntry = aCacheEntry;
 
-  mCacheId = aCacheId;
-
   SetLoadId(aLoadId);
 
   // Register our pref observer if it hasn't been done yet.
   if (NS_UNLIKELY(!gRegisteredPrefObserver)) {
     nsCOMPtr<nsIObserver> observer(new imgRequestPrefObserver());
     Preferences::AddStrongObservers(observer, kObservedPrefs);
     ReloadPrefs();
     gRegisteredPrefObserver = PR_TRUE;
@@ -357,22 +354,16 @@ nsresult imgRequest::RemoveProxy(imgRequ
   // If a proxy is removed for a reason other than its owner being
   // changed, remove the proxy from the loadgroup.
   if (aStatus != NS_IMAGELIB_CHANGING_OWNER)
     proxy->RemoveFromLoadGroup(PR_TRUE);
 
   return NS_OK;
 }
 
-PRBool imgRequest::IsReusable(void *aCacheId)
-{
-  return (mImage && mImage->GetStatusTracker().IsLoading()) ||
-    (aCacheId == mCacheId);
-}
-
 void imgRequest::CancelAndAbort(nsresult aStatus)
 {
   LOG_SCOPE(gImgLog, "imgRequest::CancelAndAbort");
 
   Cancel(aStatus);
 
   // It's possible for the channel to fail to open after we've set our
   // notification callbacks. In that case, make sure to break the cycle between
--- a/modules/libpr0n/src/imgRequest.h
+++ b/modules/libpr0n/src/imgRequest.h
@@ -89,34 +89,28 @@ public:
 
   NS_DECL_ISUPPORTS
 
   nsresult Init(nsIURI *aURI,
                 nsIURI *aCurrentURI,
                 nsIRequest *aRequest,
                 nsIChannel *aChannel,
                 imgCacheEntry *aCacheEntry,
-                void *aCacheId,
                 void *aLoadId,
                 nsIPrincipal* aLoadingPrincipal,
                 PRInt32 aCORSMode);
 
   // Callers must call imgRequestProxy::Notify later.
   nsresult AddProxy(imgRequestProxy *proxy);
 
   // aNotify==PR_FALSE still sends OnStopRequest.
   nsresult RemoveProxy(imgRequestProxy *proxy, nsresult aStatus, PRBool aNotify);
 
   void SniffMimeType(const char *buf, PRUint32 len);
 
-  // a request is "reusable" if it has already been loaded, or it is
-  // currently being loaded on the same event queue as the new request
-  // being made...
-  PRBool IsReusable(void *aCacheId);
-
   // Cancel, but also ensure that all work done in Init() is undone. Call this
   // only when the channel has failed to open, and so calling Cancel() on it
   // won't be sufficient.
   void CancelAndAbort(nsresult aStatus);
 
   // Methods that get forwarded to the Image, or deferred until it's
   // instantiated.
   nsresult LockImage();
@@ -242,18 +236,16 @@ private:
   nsTObserverArray<imgRequestProxy*> mObservers;
 
   nsCOMPtr<nsITimedChannel> mTimedChannel;
 
   nsCString mContentType;
 
   nsRefPtr<imgCacheEntry> mCacheEntry; /* we hold on to this to this so long as we have observers */
 
-  void *mCacheId;
-
   void *mLoadId;
 
   imgCacheValidator *mValidator;
   nsCategoryCache<nsIContentSniffer> mImageSniffers;
   nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
   nsCOMPtr<nsIChannel> mNewRedirectChannel;
 
   // The ID of the inner window origin, used for error reporting.