Bug 1610605 - remove use of nsAutoPtr from C-C: Part 3: nsAbWinHelper. r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Thu, 30 Jan 2020 11:12:09 +0200
changeset 38044 eca9d62cfb2ca1c44e6bae3d66776ef5613b9c28
parent 38043 36e93a246513596dae40e4ad394e3095f90fdcc7
child 38045 499ff502287d51626456f5a764d41b24b5b6dc83
push id398
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:10:28 +0000
reviewersmkmelin
bugs1610605
Bug 1610605 - remove use of nsAutoPtr from C-C: Part 3: nsAbWinHelper. r=mkmelin DONTBUILD
mailnews/addrbook/src/nsAbWinHelper.cpp
mailnews/addrbook/src/nsAbWinHelper.h
--- a/mailnews/addrbook/src/nsAbWinHelper.cpp
+++ b/mailnews/addrbook/src/nsAbWinHelper.cpp
@@ -207,35 +207,29 @@ void nsMapiEntryArray::CleanUp(void) {
     mEntries = NULL;
     mNbEntries = 0;
   }
 }
 
 using namespace mozilla;
 
 uint32_t nsAbWinHelper::mEntryCounter = 0;
-nsAutoPtr<mozilla::Mutex> nsAbWinHelper::mMutex;
-uint32_t nsAbWinHelper::mUseCount = 0;
+mozilla::StaticAutoPtr<mozilla::Mutex> nsAbWinHelper::mMutex;
 // There seems to be a deadlock/auto-destruction issue
 // in MAPI when multiple threads perform init/release
 // operations at the same time. So I've put a mutex
 // around both the initialize process and the destruction
 // one. I just hope the rest of the calls don't need the
 // same protection (MAPI is supposed to be thread-safe).
 
 nsAbWinHelper::nsAbWinHelper(void) : mLastError(S_OK), mAddressBook(NULL) {
-  if (!mUseCount++) mMutex = new mozilla::Mutex("nsAbWinHelper.mMutex");
-
   MOZ_COUNT_CTOR(nsAbWinHelper);
 }
 
-nsAbWinHelper::~nsAbWinHelper(void) {
-  if (!--mUseCount) mMutex = nullptr;
-  MOZ_COUNT_DTOR(nsAbWinHelper);
-}
+nsAbWinHelper::~nsAbWinHelper(void) { MOZ_COUNT_DTOR(nsAbWinHelper); }
 
 BOOL nsAbWinHelper::GetFolders(nsMapiEntryArray& aFolders) {
   aFolders.CleanUp();
   nsMapiInterfaceWrapper<LPABCONT> rootFolder;
   nsMapiInterfaceWrapper<LPMAPITABLE> folders;
   ULONG objType = 0;
   ULONG rowCount = 0;
   SRestriction restriction;
--- a/mailnews/addrbook/src/nsAbWinHelper.h
+++ b/mailnews/addrbook/src/nsAbWinHelper.h
@@ -5,17 +5,17 @@
 #ifndef nsAbWinHelper_h___
 #define nsAbWinHelper_h___
 
 #include <windows.h>
 #include <mapix.h>
 
 #include "nsString.h"
 #include "mozilla/Mutex.h"
-#include "nsAutoPtr.h"
+#include "mozilla/StaticPtr.h"
 
 struct nsMapiEntry {
   ULONG mByteCount;
   LPENTRYID mEntryId;
 
   nsMapiEntry(void);
   ~nsMapiEntry(void);
   nsMapiEntry(ULONG aByteCount, LPENTRYID aEntryId);
@@ -97,18 +97,17 @@ class nsAbWinHelper {
   BOOL GetDefaultContainer(nsMapiEntry& aContainer);
   // Is the helper correctly initialised?
   BOOL IsOK(void) const { return mAddressBook != NULL; }
 
  protected:
   HRESULT mLastError;
   LPADRBOOK mAddressBook;
   static uint32_t mEntryCounter;
-  static uint32_t mUseCount;
-  static nsAutoPtr<mozilla::Mutex> mMutex;
+  static mozilla::StaticAutoPtr<mozilla::Mutex> mMutex;
 
   // Retrieve the contents of a container, with an optional restriction
   BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
                    nsMapiEntry** aList, ULONG& aNbElements, ULONG aMapiType);
   // Retrieve the values of a set of properties on a MAPI object
   BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG* aPropertyTags,
                          ULONG aNbProperties, LPSPropValue& aValues,
                          ULONG& aValueCount);