Bug 1473135: Stop using ReentrantMonitor for string bundle mutexes. r?gandalf draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 20 Jul 2018 17:20:00 -0700
changeset 821094 bf5b451a7b4c02754a5f7c00c698f02b9292391b
parent 821056 f1a41c910bdd5eb4ff739d931d782f8e41c5212e
push id117014
push usermaglione.k@gmail.com
push dateSat, 21 Jul 2018 00:20:21 +0000
reviewersgandalf
bugs1473135
milestone63.0a1
Bug 1473135: Stop using ReentrantMonitor for string bundle mutexes. r?gandalf MozReview-Commit-ID: HUfb47Eei7P
intl/strres/nsStringBundle.cpp
intl/strres/nsStringBundle.h
--- a/intl/strres/nsStringBundle.cpp
+++ b/intl/strres/nsStringBundle.cpp
@@ -115,25 +115,25 @@ namespace {
  */
 class StringBundleProxy : public nsIStringBundle
 {
   NS_DECL_THREADSAFE_ISUPPORTS
 
   NS_DECLARE_STATIC_IID_ACCESSOR(STRINGBUNDLEPROXY_IID)
 
   explicit StringBundleProxy(already_AddRefed<nsIStringBundle> aTarget)
-    : mReentrantMonitor("StringBundleProxy::mReentrantMonitor")
+    : mMutex("StringBundleProxy::mMutex")
     , mTarget(aTarget)
   {}
 
   NS_FORWARD_NSISTRINGBUNDLE(Target()->);
 
   void Retarget(nsIStringBundle* aTarget)
   {
-    ReentrantMonitorAutoEnter automon(mReentrantMonitor);
+    MutexAutoLock automon(mMutex);
     mTarget = aTarget;
   }
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override
   {
     return aMallocSizeOf(this);
   }
 
@@ -141,25 +141,25 @@ class StringBundleProxy : public nsIStri
   {
     return mRefCnt == 1 ? SizeOfIncludingThis(aMallocSizeOf) : 0;
   }
 
 protected:
   virtual ~StringBundleProxy() = default;
 
 private:
-  ReentrantMonitor mReentrantMonitor;
+  Mutex mMutex;
   nsCOMPtr<nsIStringBundle> mTarget;
 
   // Atomically reads mTarget and returns a strong reference to it. This
   // allows for safe multi-threaded use when the proxy may be retargetted by
   // the main thread during access.
   nsCOMPtr<nsIStringBundle> Target()
   {
-    ReentrantMonitorAutoEnter automon(mReentrantMonitor);
+    MutexAutoLock automon(mMutex);
     return mTarget;
   }
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(StringBundleProxy, STRINGBUNDLEPROXY_IID)
 
 NS_IMPL_ISUPPORTS(StringBundleProxy, nsIStringBundle, StringBundleProxy)
 
@@ -299,17 +299,17 @@ MakeBundleRefPtr(Args... args)
 
 NS_IMPL_ISUPPORTS(nsStringBundleBase, nsIStringBundle, nsIMemoryReporter)
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsStringBundle, nsStringBundleBase)
 NS_IMPL_ISUPPORTS_INHERITED(SharedStringBundle, nsStringBundleBase, SharedStringBundle)
 
 nsStringBundleBase::nsStringBundleBase(const char* aURLSpec) :
   mPropertiesURL(aURLSpec),
-  mReentrantMonitor("nsStringBundle.mReentrantMonitor"),
+  mMutex("nsStringBundle.mMutex"),
   mAttemptedLoad(false),
   mLoaded(false)
 {
 }
 
 nsStringBundleBase::~nsStringBundleBase()
 {
   UnregisterWeakMemoryReporter(this);
@@ -590,17 +590,17 @@ nsStringBundleBase::GetStringFromAUTF8Na
   return GetStringFromName(PromiseFlatCString(aName).get(), aResult);
 }
 
 NS_IMETHODIMP
 nsStringBundleBase::GetStringFromName(const char* aName, nsAString& aResult)
 {
   NS_ENSURE_ARG_POINTER(aName);
 
-  ReentrantMonitorAutoEnter automon(mReentrantMonitor);
+  MutexAutoLock autolock(mMutex);
 
   return GetStringImpl(nsDependentCString(aName), aResult);
 }
 
 nsresult
 nsStringBundle::GetStringImpl(const nsACString& aName, nsAString& aResult)
 {
   MOZ_TRY(LoadProperties());
--- a/intl/strres/nsStringBundle.h
+++ b/intl/strres/nsStringBundle.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsStringBundle_h__
 #define nsStringBundle_h__
 
-#include "mozilla/ReentrantMonitor.h"
+#include "mozilla/Mutex.h"
 #include "nsIStringBundle.h"
 #include "nsIMemoryReporter.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsCOMArray.h"
 
 class nsIPersistentProperties;
 
@@ -50,20 +50,20 @@ protected:
     virtual ~nsStringBundleBase();
 
     virtual nsresult GetStringImpl(const nsACString& aName, nsAString& aResult) = 0;
 
     virtual nsresult GetSimpleEnumerationImpl(nsISimpleEnumerator** elements) = 0;
 
     void RegisterMemoryReporter();
 
-    nsCString              mPropertiesURL;
-    mozilla::ReentrantMonitor    mReentrantMonitor;
-    bool                         mAttemptedLoad;
-    bool                         mLoaded;
+    nsCString mPropertiesURL;
+    mozilla::Mutex mMutex;
+    bool mAttemptedLoad;
+    bool mLoaded;
 
     size_t SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const override;
 
 public:
     static nsresult FormatString(const char16_t *formatStr,
                                  const char16_t **aParams, uint32_t aLength,
                                  nsAString& aResult);
 };